let in ES6 (2)

3. Regarding the temporary dead zone: use typeof to detect an undeclared variable
, the result returned in es5 is undefined but no error is reported
, es6 directly reports an error

"use strict";
console.log(typeof num); //->undefined 当前变量不存在,但是用用typeof检测的时候,不会提示错误,而是返回undefined
console.log(typeof num);//num is not defined
let num;  ES6中检测一个没有被声明过的变量直接报错,不像之前ES5中值为undefined一样了

let num;
console.log(typeof num);//只是声明但是没有定义 所以是undefined

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326195764&siteId=291194637
Recommended