I'm fairly well-versed on the differences between es6 let
and const
in general. What I'm not so sure about, is within the definition of a for..of
loop.
I know that an "old-school" for loop signature will not accept const
ie
for (let i = 0; i < 100; i++) ... // works in chrome
for (const i = 0; i < 100; i++) ... // does not work in chrome (reassignment error)
However, with a for..of
loop, it does not seem to make a difference
const someArray = ['hello', 'hey'];
for (let elem of someArray) ... // works
for (const elem of someArray) ... // also works?
So what's going on here?
Why is const
allowed in for..of
but not an old-school for loop?
What is the ultimate result difference within the loop? (other than possibly reassigning elem
within the loop which I wouldn't expect many people to be doing regardless)