The value of a constant cannot change through re-assignment
means that it can change, but not through re-assignment.
a constant cannot be re-declared
means that if you declare it, you cannot do it again.
However if you do something like this, you can declare it multiple times:
const array = [0, 1, 2, 3];
let i = 0;
const a = array[i];
//output is: 0 1 2 3 3
Why? In this example we are exploiting the “out-of-scope” thing you say.
So to answer your questions:
Is this the case?
I don’t know if the for…of… loop uses this logic. It may be, the MDN page about this gives a couple of examples about when to use
const and when to use
let. It would make sense if it would work this way though.
Has this suspected re-declaration in the for…of loop some performance implications for more complex arrays were the elements itself are bigger objects?
I cannot say by experience as I never found myself in this situation of handling such large arrays. From a quick research on the web I didn’t find any definitive statement about this. Try searching it yourself, maybe you’re luckier than me. In any case, you can test this thesis yourself anytime, just open your browser console, load a heavy array and loop through it with different methods, see if there are any statistical relevant temporal differences and let us know!