块级作用域
?重復(fù)定義會報錯
if(true){let a = 1;let a = 2; }輸出:
Uncaught SyntaxError: Identifier 'a' has already been declared
?
嵌套循環(huán)不會相互影響
for (let i = 0; i < 3; i++) {console.log("out", i);for (let i = 0; i < 2; i++) {console.log("in", i);}}結(jié)果 out 0 in 0 in 1 out 1 in 0 in 1 out 2 in 0 in 1
?
?實現(xiàn)塊級作用域
if(true){let name = '123'; } console.log(name);?
?
不存在變量提示
console.log('inner',i);let i = 100;輸出;
Uncaught ReferenceError: Cannot access 'i' before initialization
?
轉(zhuǎn)載于:https://www.cnblogs.com/guangzhou11/p/11325778.html
總結(jié)
- 上一篇: 作用域变量 var
- 下一篇: Set 的合集 并集 差集