Students Empire

Learn Something New

Null Type

The Null type is a data type that has only one value: the special value null.

A null value is an empty object pointer, typeof returns "object" when it's passed a null value:

				var car = null; 
				console.log(typeof car);   //"object" 

When defining a variable that is meant to later hold an object, it is good practice to initialize the variable to null.

Then, you can check for the value null to determine if the variable has been filled with an object reference:

				if (car != null){ 
				    //do something with car 

The value undefined is a derivative of null:

				console.log(null == undefined);   //true 

Using the equality operator (==) between null and undefined always returns true, though keep in mind that this operator converts its operands for comparison purposes.

null vs undefined

You should never explicitly set the value of a variable to undefined.

Any time an object is declared but is not available, null should be used in its place.