实例
null 和 undefined 的值相等,但类型不等:
typeof undefined // undefined
typeof null // object
null === undefined // false
null == undefined // true
-
在 JavaScript 中 null 表示 "什么都没有"。
null是一个只有一个值的特殊类型。表示一个空对象引用,用 typeof 检测 null 返回是object。
var person = null; // 值为 null(空), 但类型为对象 -
在 JavaScript 中, undefined 是一个没有设置值的变量。
typeof 一个没有值的变量会返回 undefined。
var person; // 值为 undefined(空), 类型是undefined任何变量都可以通过设置值为 undefined 来清空, 类型为 undefined。
person = undefined; // 值为 undefined, 类型是undefined