Closures in a for loop and lexical environment
The i inside your function is evaluated when the function is executed, not when you assign it to onload. Your for loop has already completed by the time any of your onload functions fire, so all of them see the final value N. To capture the current value of i, you need to pass it … Read more