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

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -