Why is javascript like this? alert(1=="1")--> true alert(1=="hello")--> true alert("1"=="hello")--> false | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why is javascript like this? alert(1=="1")--> true alert(1=="hello")--> true alert("1"=="hello")--> false

Please click like button

10th Jun 2019, 1:00 PM
Ferry
Ferry - avatar
3 Answers
+ 1
Ferry, I highly suggest you visit this MDN page, it will give you a better/deeper understanding of loose and strict equality. Reference https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness (==) - Abstract Equality Comparison ("loose equality", "double equals"), will perform a type conversion when comparing two things. Loose equality compares two values for equality, after converting both values to a common type. (===) - Strict Equality Comparison ("strict equality", "identity", "triple equals"), will do the same comparison as double equals, but without type conversion. Strict equality compares two values for equality. Neither value is implicitly converted. If the values have different types, the values are considered unequal.
11th Jun 2019, 12:45 PM
ODLNT
ODLNT - avatar
+ 1
ODLNT Thank you very much
11th Jun 2019, 5:39 AM
Ferry
Ferry - avatar
0
That is crazy!??
10th Jun 2019, 1:01 PM
Ferry
Ferry - avatar