var proto = Object.getPrototypeOf(Object.getPrototypeOf({}));
// But this returns undefined:
Object.getOwnPropertyDescriptor({}, "a");
所有其他不存在的情况都表示为未定义(如@Axel所述)。以下每个打印“未定义”:
var uninitalised;console.log(uninitalised);
var obj = {};console.log(obj.nonExistent);
function missingParam(missing){console.log(missing);}
missingParam();
var arr = [];console.log(arr.pop());
var game = null; //typeof(game) is "object"
game.score = 100;//null is not an object, what the heck!?game instanceof Object; //false, so it's not an instance but it's type is object//let's make this primitive variable an object;game = {};typeof(game);//it is an objectgame instanceof Object; //true, yay!!!game.score = 100;
未定义的情况:
var score; //at this point 'score' is undefinedtypeof(score); //'undefined'var score.player = "felix"; //'undefined' is not an objectscore instanceof Object; //false, oh I already knew that.
let a;console.log(a); //undefined, since it is declared but not initialized
console.log(null == undefined) //trueconsole.log(null === undefined) // false
console.log(typeof null) //objectconsole.log(typeof undefined) //undefined