JS: null

By Xah Lee. Date: . Last updated: .

What is null

typeof null

typeof null return "object". (this is a historical bug. typeof null should return "null" )

typeof null === "object"

Why “typeof null” return "object"

typeof null return "object" is a historical implementation bug. Now we are stuck with it.

null is not a object, because It doesn't have the defining quality of JavaScript objects, namely, it's not a collection of (key and value) pairs; you cannot add properties to null.

// null.p = 4;
// TypeError: Cannot set property 'p' of null

What is the Use of null

There are 2 major uses of null.

JavaScript, Special Literals