undefined是一個特殊的值,它表明沒有。嗯,不是說真的沒有,它就像小強同樣無所不在,但你又抓不住它,由於它是沒有。。。typescript
var arr = [1, 2, 3]; console.log(arr[4]); // undefined
var a; console.log(a); // undefined
function callMe(name) { return name; } console.log(callMe()); // undefined
function callMe(name) { // do nothing } console.log(callMe('原罪')); // undefined
var def = {hello: "world"}; console.log(def.hi); // undefined
堆內存和棧內存的千絲萬縷數組
function doYouLikeMe(You) { delete You.amPower; return 'no'; } var I = {name: "原罪", amPower: 'yes'}; console.log(I.amPower); // 'yes' console.log(doYouLikeMe(I)); // 'no' console.log(I.amPower); // undefined
亞當和夏娃偷吃禁果,犯了原罪es5
function whatAboutAdam(eve) { eve.pop(); return '無罪釋放'; } var eve = ['夏', '娃', '的', '原', '罪']; console.log(eve[4]); // '罪' console.log(whatAboutAdam(eve)); // '無罪釋放' console.log(eve[4]); // undefined
var a; console.log(typeof a); // "undefined" console.log(typeof undefined); // "undefined" console.log(typeof notDefinedKey); // "undefined"
隊友,能夠用 ===
對比插件
// void後面加上任何值都會 全等於 undefined void 0 === undefined // true void 1 === undefined // true void '原罪' === undefined // true void true === undefined // true void {} === undefined // true
敵人,能夠用 ==
對比:code
null == undefined // true null === undefined // false
敵人的敵人,須要取反
對比:ip
!false === !undefined // true !"" === !undefined // true !0 === !undefined // true false == undefined // false "" == undefined // false 0 == undefined // false
undefined不是保留字,es5以後,全局undefined沒法被覆蓋內存
undefined = 2; console.log(undefined); // undefined
嚴格模式下,覆蓋全局undefined將直接拋錯get
"use strict"; undefined = 2; console.log(undefined); // throw new TypeError();
但局部undefined還能夠被覆蓋(包括嚴格模式)it
var undefined = 2; console.log(undefined); // 2
===
,兩個等於號的就忘了它吧