I was doing the exercises on the for … of article in JavaScript Syntax, Part 2: Loops and was wondering why a type error isn’t being returned. I assumed that since in each iteration when the value changes the same rules would apply if i declared const fruit = ‘apple’ and tried to change it to const fruit = ‘banana’;
That does seem counter-intuitive. Check out the MDN documentation.
It doesn’t really give a solid explanation as to why const can be used, but does show an example where using let would be necessary. It seems to me that with each iteration, a new declaration occurs rather than assigning the next value to the already declared const variable.