JavaScript参考手册
全球对象 | Global Objects
null
是一个 JavaScript 字面量,表示空值(null or an "empty" value),即没有对象被呈现(no object value is present)。它是 JavaScript原始值之一
语法
null
描述
null
是一个字面量(而不是全局对象的一个属性,undefined
是)。在 APIs 中,null
常被放在期望一个对象,但是不引用任何对象的参数位置。当检测 null 或 undefined 时,注意相等(==)与全等(===)两个操作符的区别 (前者会执行类型转换)。
// 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
与 undefined
的不同点:
当检查null
或 undefined
时, 请注意相等 (==) 和标识 (===) 运算符之间的差异, 因为前者执行类型转换。
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. |
Living Standard |
|
浏览器兼容性
Feature |
Chrome |
Edge |
Firefox (Gecko) |
Internet Explorer |
Opera |
Safari |
---|---|---|---|---|---|---|
Basic support |
(Yes) |
(Yes) |
(Yes) |
(Yes) |
(Yes) |
(Yes) |
Feature |
Android |
Chrome for Android |
Edge |
Firefox Mobile (Gecko) |
IE Mobile |
Opera Mobile |
Safari Mobile |
---|---|---|---|---|---|---|---|
Basic support |
(Yes) |
(Yes) |
(Yes) |
(Yes) |
(Yes) |
(Yes) |
(Yes) |
全球对象 | Global Objects相关
JavaScript 是一种高级编程语言,通过解释执行,是一门动态类型,面向对象(基于原型)的解释型语言。它已经由ECMA(欧洲电脑制造商协会)通过 ECMAScript 实现语言的标准化。它被世界上的绝大多数网站所使用,也被世界主流浏览器( Chrome、IE、FireFox、Safari、Opera )支持。JavaScript 是一门基于原型、函数先行的语言,是一门多范式的语言,它支持面向对象编程,命令式编程,以及函数式编程。它提供语法来操控文本、数组、日期以及正则表达式等,不支持 I/O,比如网络