JavaScript ES6+: var, let, or const?
Eric Elliott
51217

I think you missed the most important point of using ‘const’ instead of ‘var’ is how it relate to the concept of closure.

Check out the “The Infamous Loop Problem” at

If you use let or const in the code, instead of var, the issue will be gone.

For example, add this

let index = i

or

const index = i

….

alert(index)