+ 6
Difference between == and ===
What is the exact difference between == and === ? Could you make an example?
2 odpowiedzi
+ 14
== compares only VALUE.
2 == "2"; // true
=== compares value AND data type
2 === "2"; // false
+ 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