Junior — Senior
Closure behavior in a loop when using var
livecode
Task condition
Determine what output will be obtained after executing the following code, considering the features of closures and the scope of the variable declared with var.
var i = 10;
var array = [];
while (i--) {
array.push(function () {
return i + 1;
});
}
console.log({
0: array[0](),
1: array[1]()
});