Why if 0=="0" in javascript return true | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why if 0=="0" in javascript return true

if(0=="0") alert("true"); else alert("false");

31st Mar 2018, 5:16 PM
kamlesh parmar
kamlesh parmar - avatar
2 Answers
+ 6
== checks if they both are same values not data type. Use === in this case which will check values and data type also all you need to do is alert(0 === "0"); because the browser will return true or false for you
31st Mar 2018, 5:24 PM
TurtleShell
TurtleShell - avatar
+ 4
it just compares if both are equal to or not and does not care about the data type of both. you can use === for checking data type.
31st Mar 2018, 5:25 PM
G.S.N.V. Suraj
G.S.N.V. Suraj - avatar