码迷,mamicode.com
首页 > 其他好文 > 详细

null 理解

时间:2019-04-26 00:01:20      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:定义   string   ada   lob   .com   现在   iter   profile   top   

值 null 特指对象的值未设置。它是 JavaScript 基本类型 之一。

语法

null

描述

值 null 是一个字面量,它不像undefined 是全局对象的一个属性。null 是表示缺少的标识,指示变量未指向任何对象。把 null 作为尚未创建的对象,也许更好理解。在 APIs 中,null 常在返回类型是对象,但没关联值的地方使用。

// foo不存在,它从来没有被定义过或者是初始化过:
foo;
"ReferenceError: foo is not defined"

// foo现在已经是知存在的,但是它没有类型或者是值:
var foo = null; 
foo;
null

null 与 undefined 的不同点:

当检测 null 或 undefined 时,注意相等(==)与全等(===)两个操作符的区别 ,前者会执行类型转换:

typeof null        // "object" (因为一些以前的原因而不是‘null‘)
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

规范

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

 

ECMAScript Latest Draft (ECMA-262)
null value
Draft  

浏览器兼容性

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!
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support (Yes) (Yes) (Yes) (Yes) (Yes)

相关链接

文档标签和贡献者

 标签:  

null 理解

标签:定义   string   ada   lob   .com   现在   iter   profile   top   

原文地址:https://www.cnblogs.com/lcspring/p/10771852.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!