看看这段代码;为什么不满足(a === typeof a)
var a;
(a === undefined)?console.log("a is undefined"):null;
(typeof a === 'undefined')?console.log("typeof a is 'undefined'"):null;
答案 0 :(得分:2)
根据https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof typeof
总是返回一个字符串。
答案 1 :(得分:1)
由于:
var a;
typeof a === 'undefined';
a === undefined;
一个是字符串值为'undefined'
的字符串,一个是undefined
原语。那两个不一样。
typeof x
始终返回字符串值,例如"undefined"
,"boolean"
,"string"
,"object"
等....