In Javascript, == “” evaluates to true. Why is it so?

后端 未结 8 1596
野性不改
野性不改 2020-12-13 22:18

If I do 0 == \"0\" it evaluates to true. Try,

if( -777 == \"-777\" ) alert(\"same\");

alert happens.

And, it\'s also noticeable th

8条回答
  •  暖寄归人
    2020-12-13 22:25

    Javascript doesn't cast "false" to boolean false, only to the string "false".

    You can loosely cast string values to their integer equivalent, thus your first example works.

提交回复
热议问题