NULL in Javascript

A variable is a storage location that contains a value. A null represents nothing . Its not an actual value. It means that the storage location does not contain anything (but null itself is just a special kind of value).

What's the typeof null?

The null value is technically a primitive , the way "object" or "number" are primitives. This would typically mean that the type of null should also be "null". However, this is not the case because of a peculiarity with the way JavaScript was first defined.

Why is null considered an object in JavaScript?

Actually null is not an object , it is a primitive value. For example, you cannot add properties to it. Sometimes people wrongly assume that it is an object, because typeof null returns "object".

It is a JavaScript design error they can't fix now (that might even be fixed in ECMAScript 6). It should have been type null , not type object, or not have it at all. It necessitates an extra check (sometimes forgotten) when detecting real objects and is source of bugs.
 (C) 2022    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.
SiteMap  | Terms  | About