null
The value null
represents the intentional absence of any object value. It is one of JavaScript's primitive values (en-US).
語法
null
描述
The value null
is written with a literal, null
(it's not an identifier for a property of the global object like undefined
can be). In APIs, null
is often retrieved in place where an object can be expected but no object is relevant. When checking for null or undefined beware of the differences between equality (==) and identity (===) operators (type-conversion is performed with the former).
// 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"
Difference between null
and undefined
typeof null // object (bug in ECMAScript, should be null)
typeof undefined // undefined
null === undefined // false
null == undefined // true
規範
Specification |
---|
ECMAScript Language Specification # sec-null-value |
瀏覽器相容性
BCD tables only load in the browser