<分区>
一般来说,我相当精通 es6 let
和 const
之间的区别。我不太确定的是 for..of
循环的定义。
我知道“老式”for 循环签名不会接受 const
即
for (let i = 0; i < 100; i++) ... // works in chrome
for (const i = 0; i < 100; i++) ... // does not work in chrome (reassignment error)
但是,对于 for..of
循环,它似乎并没有什么不同
const someArray = ['hello', 'hey'];
for (let elem of someArray) ... // works
for (const elem of someArray) ... // also works?
那么这里发生了什么?
为什么 for..of
中允许使用 const
而不是老式的 for 循环?
循环内的最终结果差异是什么? (除了可能在循环内重新分配 elem
之外,无论如何我都不希望很多人这样做)