ES5中typeof
被视为安全的,因为当检查非声明值时,它不会抛出ReferenceError
,例如:
console.log(typeof undeclaredVar); // undefined
然而,在ES6中检查typeof undeclaredLetConst
时,只有在后来使用let
或const
声明了该变量时,才会抛出错误。如果使用var
声明,则不会出现错误。
console.log(typeof undeclaredLetConst);
let undeclaredLetConst = "hello"; // ReferenceError
那里发生了什么?
typeof
? - doubleOrt