Please note, this is a STATIC archive of website developer.mozilla.org from November 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

null

概述

值 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 的不同点:

typeof null        // object (bug in ECMAScript, should be null)
typeof undefined   // undefined
null === undefined // false
null  == undefined // true
 
 
 
 

规范

规范版本 规范状态 注解
ECMAScript 1st Edition. Standard Initial definition.
ECMAScript 5.1 (ECMA-262)
null value
Standard  
ECMAScript 2015 (6th Edition, ECMA-262)
null value
Standard  

浏览器兼容性

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)

相关链接

文档标签和贡献者

 此页面的贡献者: SphinxKnight, ziyunfei, AlexChao, teoli
 最后编辑者: SphinxKnight,