null
De waarde null
representeert het moedwillig weglaten, of de bedoelde afwezigheid van welk object of waarde dan ook. Het is een van JavaScript's primitive values.
Syntax
null
Beschrijving
De waarde null
wordt letterlijk geschreven als null
(het is geen idenfifier voor een eigenschap van de global object zoals undefined
(en-US) wel kan zijn). In APIs, wordt null
vaak verkregen op plekken waar een object mag worden verwacht, maar waar tegelijk geen object relevant is . Wanneer op null of undefined wordt gecontroleerd, wees dan bewust van de verschillen tussen equality (==) en identity (===) operators (type-conversie wordt via de eerste bereikt).
// 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"
Verschil tussen null
en undefined
typeof null // object (bug in ECMAScript, should be null)
typeof undefined // undefined
null === undefined // false
null == undefined // true
Specificaties
Specificatie | Status | Commentaar |
---|---|---|
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 (ECMA-262) The definition of 'null value' in that specification. |
Living Standard |
Browser compatibiliteit
We're converting our compatibility data into a machine-readable JSON format.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
Find out how you can help! (en-US)
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |