問題文
A loop creates one function per iteration and each function must remember the value of the loop counter at the time it was created. Which two statements are correct? (Select two.)
選択肢
- Declaring the counter with let gives every iteration its own binding, so each function remembers a different value.
- Declaring the counter with var gives all the functions the same binding, so they all read the final value.
- The functions capture the value of the counter at creation time regardless of how it was declared, because a closure copies the values it needs.
- Wrapping the body in an immediately invoked function expression that takes the counter as a parameter has no effect, because the parameter refers to the same binding as the loop variable.
- Using const for the loop counter of a counting loop solves the problem because the counter then cannot change at all during the iteration.