null

Thenullvalue represents the intentional absence of any object value. It is one of JavaScript'sprimitive valuesand is treated asfalsyfor boolean operations.

Try it

Syntax

js
null

Description

The valuenullis written with a literal:null. nullis not an identifier for a property of the global object, like undefinedcan be. Instead, nullexpresses a lack of identification, indicating that a variable points to no object. In APIs,nullis often retrieved in a place where an object can be expected but no object is relevant.

js
// foo does not exist. It is not defined and has never been initialized:
foo;//ReferenceError: foo is not defined
js
// foo is known to exist now but it has no type or value:
constfoo=null;
foo;//null

Examples

Difference betweennullandundefined

When checking fornullorundefined,beware of thedifferences between equality (==) and identity (===) operators,as the former performs type-conversion.

js
typeofnull;// "object" (not "null" for legacy reasons)
typeofundefined;// "undefined"
null===undefined;// false
null==undefined;// true
null===null;// true
null==null;// true
!null;// true
Number.isNaN(1+null);// false
Number.isNaN(1+undefined);// true

Specifications

Specification
ECMAScript Language Specification
#sec-null-value

Browser compatibility

BCD tables only load in the browser

See also