What does 'fresh binding per iteration' mean for let in a loop?
The spec says each iteration of a let-based for loop gets a new copy of the loop variable. Conceptually, the engine copies the current value into a new i at the start of each iteration, so each closure captures a distinct i.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in let and const in Loops: The Closure Fix
Because let creates a fresh binding of the loop variable per iteration. Each callback closes over its own copy of i, which holds the value for that iteration. With var, all callbacks share one i, which is the final value by the time they run.
No. const i = 0; i++; throws TypeError because i++ reassigns i, and const does not allow reassignment. Use let for classic for loop counters.
Yes. Each iteration of for...of creates a fresh binding, and the loop variable does not change within an iteration. const is appropriate and preferred for for...of and for...in.
Still have questions?
Browse all our FAQs or reach out to our support team
