Difference between == and === | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

Difference between == and ===

What is the exact difference between == and === ? Could you make an example?

13th Apr 2018, 1:18 PM
Giulia I.
Giulia I. - avatar
2 Answers
+ 14
== compares only VALUE. 2 == "2"; // true === compares value AND data type 2 === "2"; // false
13th Apr 2018, 1:21 PM
777
777 - avatar
+ 5
== (equality) determines whether two expressions have the same value, possibly applying the appropriate conversions between types to make the comparison, while === (identity) determines if two expressions have the same value but without making conversions (the two terms compared must therefore be of the same type). i.e 8 == '8' returns true, while 8 === '8' returns false, this because '8' is a string but 8 without quotes is a number. In javascrpit it is recommended to use the === operator because makes the code more clear and precise. I hope I was helpful
13th Apr 2018, 1:47 PM
Gianni P.
Gianni P. - avatar