Why in JavaScript, “if ('0' == false)” is equal to false whereas it gives true in “if(0)” statement?
Answers
Answered by
0
Answer :
The reason is because when you explicitly do "0" == false, both sides are being converted to numbers, and then the comparison is performed.
When you do: if ("0") console.log("ha"), the string value is being tested. Any non-empty string is true, while an empty string is false.
Similar questions