Because your anonymous function function(){return i;} is not executed, i here is undefined, and then return arr, this is function(){return i;} stored in the array. When you getNum[0]( ) is when the above for (var i = 0, arr=[];i<3;i++){} is executed, i=3; so getNum[0](),getNum[1](),getNum[2 ]() outputs all 3.
Because i is a peripheral variable, it is only found when calling. And when you call it, the loop has ended and the value of i is already 3, so you can only get 3
Because your anonymous function function(){return i;} is not executed, i here is undefined, and then return arr, this is function(){return i;} stored in the array. When you getNum[0]( ) is when the above for (var i = 0, arr=[];i<3;i++){} is executed, i=3; so getNum[0](),getNum[1](),getNum[2 ]() outputs all 3.
That’s right now. The closure problem is solved in the same way
Because i is a peripheral variable, it is only found when calling.
And when you call it, the loop has ended and the value of i is already 3, so you can only get 3
Problem of defining domain
var changed to let