javascript - Why does null == undefined evaluate to true? -
i have code below not clear me
var = null; if(a==undefined) alert("true"); else alert("false");
when ran above code alerts true.
can explain whats reason or concept behind this?
it's true because ==
loose equality operator, , null
, undefined
loosely equal (null == undefined
true). if use strict equality operator, ===
, not equal (null === undefined
false).
basically, loose equality operator coerce operands if they're of different types (see abtract equality comparison in spec). 0 == ""
true, instance, because if coerce ""
number, it's 0
. strict equality operator considers operands of different types not equal (see strict equality comparison); not coerce.
Comments
Post a Comment