Explain these conditions in JS? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Explain these conditions in JS?

(0=="0") is true. (0==[ ]) is true. ("0"==[ ]) is false. Why? https://code.sololearn.com/WN384S96WWIU/?ref=app

1st Apr 2018, 7:38 AM
Sayan Kundu
2 Answers
+ 2
0 == "0" is true because "0" string converted to number is 0 0 == [ ] is true because empty arrays and empty strings are treated as false, and so is 0 (then false == false) "0" == [ ] is false because non empty strings are treated as true and empty array as true (then true != false)
1st Apr 2018, 9:26 AM
visph
visph - avatar
1st Apr 2018, 7:46 AM
Sayan Kundu