JS: null
What is null
nullis a literal expression, e.g. you can writelet x = null;nullis one of the type of JavaScript values, and it is the only value of that type. [see Value Types]
typeof null
typeof null return "object".
(this is a historical bug.
typeof null should return "null"
)
console.assert(typeof null === "object");
Why typeof null return object
What is the Use of null
There are 2 major uses of null.
- you can set a object's prototype (parent) to
null, to make it having no prototype. [see Get Set Prototype] Or, use Object.create withnullto create a object with no parent. - You can set a variable to
nullas default initial value. (unassigned variable has default value ofundefined. [see undefined]).