1.都會轉成falsejavascript
if(!undefined){ console.log('undefined') } if(!null){ console.log('null') } //輸出 undefined null
2.並且使用相等來判斷,是相等的html
console.log(undefined == null)//true console.log(undefined === null) //false
3.它們都是數據類型,並且它們都只有一個值。java
感謝阮一峯老師的解答:http://www.ruanyifeng.com/blog/2014/03/undefined-vs-null.html函數
1.null是一個表示"無"的對象,轉爲數值時爲0;undefined是一個表示"無"的原始值,轉爲數值時爲NaN。spa
Number(null); //0 5+null; //5 Number(undefined);// NaN 5 + undefined;// NaN
Object.getPrototypeOf(Object.prototype)// null
變量被聲明瞭,但沒有賦值時,就等於undefined。prototype