1.2 Null、Undefined、NAN的区别
1、Undefined
Undefined是全局对象的一个属性,表示没有定义值的变量,比如说
var a;
console.log(a);//undefined
2、Null
Null表示一个空指针。
是一个Javascript字面量,表示空值。null常被放在期望一个对象,但是不引用任何对象的参数位置。
var foo=null;
console.log(foo);//null
对还未确定引用对象的指针赋值null,是一种比较好的写法。
typeof null //object
因此很多时候把null也当作object
3、NAN
NAN是Number中的特殊值,表示在由其他数据类型转换为Number的时候出现问题。
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