Null

In JavaScript null is "nothing". It is supposed to be something that doesn't exist. Unfortunately, in JavaScript, the data type of null is an object. You can empty an object by setting it to null:

  var person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"};  <=== The value is defined, type is an object
  var person = null;  <=== The value is null, but type is still an object


You can also empty an object by setting it to undefined:

  var person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"};  <=== The value is defined, type is an object
  var person = undefined;  <=== The value is empty and undefined, and the type is undefined as well


You can consider it a bug in JavaScript that typeof null is an object. It should be null.

Back Table of Contents Next