小编zyp*_*zyp的帖子

What's the action scope of for-loop in ES6?

What's exactly the action scope of let in a for-loop in JavaScript?

for (let i = 0; i < 3; i++) {
  let i = 4;
  console.log(i);
}
console.log(i);
Run Code Online (Sandbox Code Playgroud)

The external console.log throws an error:

"Uncaught Reference Error: i is not defined"

It proves i is in a block action scope, however, why doesn't the i defined in the for-loop throw any duplicate definition error?

javascript for-loop

10
推荐指数
1
解决办法
111
查看次数

标签 统计

for-loop ×1

javascript ×1