The null type is an empty object pointer and therefore the typeof operator will return object when a variable is passed a value of null.

The suggestion is to pre-set a variable to a null if that same variables is intended to be used as an object later on in the code.

Essentially null is related to undefined (null == undefined) but is not the same. As explained above, the type null is an empty object pointer.

This example shows the relationship between these two data types:

alert(null == undefined); // result is TRUE

alert(null === undefined); // result is FALSE

To understand better the comparisons shown above, visit the chapter "Equality Operators".


›› go to examples ››