草庐IT

undeclaredLetConst

全部标签

javascript - ES6 typeof 抛出错误

ES5typeof被认为是安全的,因为当再次检查未声明的值时,它不会抛出ReferenceError。比如console.log(typeofundeclaredVar);//undefined但是,当在es6中检查typeofundeclaredLetConst时,如果稍后使用let或常量。如果它是用var声明的,它将正常工作。console.log(typeofundeclaredLetConst);letundeclaredLetConst="hello";//ReferenceError那里发生了什么? 最佳答案 为什么它适