JavaScript closure inside loops – simple practical example
Well, the problem is that the variable i, within each of your anonymous functions, is bound to the same variable outside of the function. ES6 solution: let ECMAScript 6 (ES6) introduces new let and const keywords that are scoped differently than var-based variables. For example, in a loop with a let-based index, each iteration through … Read more