null
是字面量同时也是语言中的关键字,用来表示无法识别的对象值,无值(no value);
undefined
实际上代表了不存在的值(non-existence of a value);
相同:
1.上下文都识别为false;等于号相等;全等于号不等;
不同:
1.void
操作符也可以返回一个undefined
值:undefined === void 0;
2.undefined
是一个预定义的全局变量(不像null
关键字) :undefined in window;
3.type of null返回“object”,通常用作一个空引用一个空对象的预期,就像一个占位符;
4.
Object.prototype.toString.call(null); // [object Null]
Object.prototype.toString.call(undefined); // [object Undefined]
参考文章地址:
http://www.ituring.com.cn/article/66892