What is the difference between '==' & '===' operators? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 24

What is the difference between '==' & '===' operators?

27th Apr 2020, 3:40 PM
Gone
28 Answers
+ 10
== equal to comparison === Identical(equal and of the same type)
28th Apr 2020, 8:04 PM
MESHACK MUTINDA
MESHACK MUTINDA - avatar
+ 7
== this check only value but === this check value and data type. Ex 2===2 same value and same data type but 2=="2" same value but not same data type.
29th Apr 2020, 8:58 AM
Anil Kumar Singh
Anil Kumar Singh - avatar
+ 6
"1" == 1 is true. But "1" === 1 is false.
27th Apr 2020, 3:43 PM
šŸ‡®šŸ‡³VivekšŸ‡®šŸ‡³
šŸ‡®šŸ‡³VivekšŸ‡®šŸ‡³ - avatar
+ 3
==Ā is used for comparisonĀ betweenĀ two variables irrespective of the datatype of variable.Ā ===Ā is used for comparisionĀ betweenĀ two variables but this will check strict type, which means it will check datatype and compare two values.
28th Apr 2020, 9:09 AM
Sketch
Sketch - avatar
+ 3
== is used to conpare two values === is used to compare two values and their type
28th Apr 2020, 9:36 PM
Bartek Wilk
Bartek Wilk - avatar
27th Apr 2020, 3:43 PM
Bahhaāµ£
Bahhaāµ£ - avatar
+ 2
== only compares the values but === compares values and types For example: $a = 1; $b = "1"; $a == $b ; returns TRUE because the both have the same value that is 1 $a === $b; returns FALSE because the value of $b wrote in double quotation " " and it's defined as string type while the $a value has not quotation and defined as integer So and integer is not same as string type and it returns false
29th Apr 2020, 10:53 AM
Amir Hossein mahdioun
Amir Hossein mahdioun - avatar
+ 2
If the comparison is between the same value type both == and === do exactly the same thing. If the value types being compared are different the == differs from === in that it allows type conversion before the comparison.By default the non-number values ("5",true,false) to be converted to numbers (5,1,0) before the comparisons are made. For more details see https://github.com/Li-YangZhong/You-Dont-Know-JS/blob/2nd-ed/get-started/ch2.md here
29th Apr 2020, 12:27 PM
Sona
Sona - avatar
+ 2
== compares only the value. === compares value and type. e.g. 5 == "5" is true. 5 === "5" is not true.
29th Apr 2020, 1:04 PM
Md. Niamul Ahad Chowdhury
Md. Niamul Ahad Chowdhury - avatar
+ 2
== checks two variables same or not, it doesn't check the data type. === checks two variables same or not and the data type must have to be same. "1" == 1 it will return true. Here the 1st 1 is string and the 2nd 1 is integer. It is true because the values are same. "1" === 1 it will return false. Though the values are same but the data types doesn't match.
29th Apr 2020, 1:53 PM
Avishek Saha
Avishek Saha - avatar
+ 2
'==' denote equal to For example : 10==10; its true And '===' its identically equal to and same For example 10===10
29th Apr 2020, 2:40 PM
ASHITOSH Ghate
ASHITOSH Ghate - avatar
+ 1
Thanks
27th Apr 2020, 3:45 PM
Gone
+ 1
Sorry
27th Apr 2020, 3:46 PM
Gone
+ 1
Jitendra Kumar No need to be sorry. Don't say that.. Its just information and a request giving to you.. Because dublicates may gets deleted by mods to keep search bar, & SL clean.. So information only..
27th Apr 2020, 3:51 PM
Jayakrishna šŸ‡®šŸ‡³
+ 1
== only checks the content if they match. Like string "1" & integer 1. It will return true because content is same though data types are not same. But === also checks if they are of same data type,which in above case is not true, as "1" is string & 1 is number. So that will return false now.
27th Apr 2020, 4:53 PM
Rohit Wadhwa
+ 1
JavaScript has an incredibly weird typesystem. To fix this, == will check if they are the same regardless of type whilst === will check the type. Examples: ā€˜0ā€™ == 0 // True ā€˜0ā€™ === 0 // False 0 == 0 // True 0 === 0 //True. I do not know much about JS other than the bare basics, but Iā€™d imagine that you should use === instead of == most of the time.
27th Apr 2020, 5:45 PM
s.f
+ 1
double equal is for compare '5' == 5 --> true three equal is identical '5' === 5 --> false Show '5' is a string, but 5 is int.
29th Apr 2020, 12:22 AM
Josshual A. Toro M.
Josshual A. Toro M. - avatar
+ 1
Thanks
29th Apr 2020, 5:33 AM
Gone