-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Labels
Description
Null 与 Undefined
null表示已被赋值,但值为空,即将一个变量显式赋值为null是正常的undefined表示已声明还未定义的变量 或 对象上不存在的属性,故将变量或属性显式赋值为undefined是不正常的null和undefined转换为布尔值均为falsenull转换为数值为0,undefined转换为数值为NaNnull == undefined,因为ECMAScript定义如此,并没有发生隐式类型转换ECMAScript中定义 "If x is null and y is undefined, return true."
详见ECMAScript#abstract-equality-comparisonnull !=== undefined,二者不是同一数据类型
// bad
let a = undefined
// good
let a