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
Explaining JavaScript scope and closures
I thought I'd try to explain something which many people struggle with: JavaScript scope and closures. There are a…robertnyman.com
I thought I'd try to explain something which many people struggle with: JavaScript scope and closures. There are a…robertnyman.com
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)