null
and undefined
are distinct concepts. When a variable is defined with var but not initialized, it holds the value of undefined
, not null
. On the other hand, null
signifies that the variable exists and has been set to the specific value null
, which is unique in its own right.
The equality operator in JavaScript has its flaws. Crockford observed that it lacks transitivity, prompting him to always recommend using the strict equality operator (===). To illustrate, here's a comparison table from '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