read an article in ES6 today:
var a = [];
for (let i = 0; i < 10; iPP) {
a[i] = function () {
console.log(i);
};
}
a[6](); // 6
The document says that in the above code, the variable I is declared by let, and the current I is only valid in this loop, so the I of each loop is actually a new variable, so the final output is 6.
but isn"t a [6] function () {console.log (i)}? When running a [6] (), since I is declared by let and is only valid in block-level scope, shouldn"t I print out undefined? How could it be six?