null
and undefined
are two different concepts. undefined
is the lack of value (if you define a variable with var without initializing it, it doesn't contain null
, but undefined
), while with null
the variable exists and is initialized with the value null
, which is a special type of value.
JavaScript equality operator is broken though, Crockford found out that it lacks transitivity and for this reason suggests to use always the strict equality (===). Consider this table published in Javascript the good parts:
'' == '0' // false
0 == '' // true
0 == '0' // true
false == 'false' // false
false == '0' // true
false == undefined // false
false == null // false
null == undefined // true