js-gotchas
JavaScript Gotchas and Common Mistakes
-
0
is falsy but"0"
is true.if (0) { console.log('yey.'); } else { console.log('boom'); // this will be printed } if ("0") { console.log('yey.'); // this will be printed } else { console.log('boom'); }
-
NaN is not a NaN.
NaN === NaN // false
During the evaluation of a tripple equals
a === b
following things are considered. FYItypeof NaN
isnumber
- If
typeof a
is different fromtypeof b
, returnfalse
. - If
typeof a
isnumber
, then- If a is NaN, return
false
. - If b is NaN, return
false
.
- If a is NaN, return
- If