The value null
represents the intentional absence of any object value. It is one of JavaScript's primitive values.
null
The value null
is written with a literal: null
. null
is not an identifier for a property of the global object, like undefined
can be. Instead, null
expresses a lack of identification, indicating that a variable points to no object. In APIs, null
is often retrieved in a place where an object can be expected but no object is relevant.
// foo does not exist. It is not defined and has never been initialized: foo; "ReferenceError: foo is not defined" // foo is known to exist now but it has no type or value: var foo = null; foo; "null"
null
and undefined
When checking for null
or undefined
, beware of the differences between equality (==) and identity (===) operators, as the former performs type-conversion.
typeof null // "object" (not "null" for legacy reasons) typeof undefined // "undefined" null === undefined // false null == undefined // true null === null // true null == null // true !null // true isNaN(1 + null) // false isNaN(1 + undefined) // true
Specification | Status | Comment |
---|---|---|
ECMAScript 1st Edition (ECMA-262) | Standard | Initial definition. |
ECMAScript 5.1 (ECMA-262) The definition of 'null value' in that specification. | Standard | |
ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'null value' in that specification. | Standard | |
ECMAScript Latest Draft (ECMA-262) The definition of 'null value' in that specification. | Draft |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | Yes | Yes | 1 | Yes | Yes | Yes |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | Yes | Yes | Yes | 4 | Yes | Yes | Yes |
Server | |
---|---|
Node.js | |
Basic support | Yes |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null