EasyClosures & Scope💻 Output Question

let in loop — each iteration gets own binding

💡

Hint

let creates a fresh binding per loop iteration — the solution to the classic var closure bug.

What does this output?

for (let i = 0; i < 3; i++) {
  setTimeout(() => console.log(i), 0);
}

Correct Output

0
1
2

Why this output?

Explanation: let creates a new binding per loop iteration. Each callback closes over its own independent i.

Key Insight: let creates a fresh binding per loop iteration — the solution to the classic var closure bug.

More Closures & Scope Output Questions

EasyClassic var in loop with setTimeoutMediumIIFE captures loop variableMediumClosure mutation persists across callsEasylet block scope — inner does not leak

Practice predicting output live →

66 output questions with instant feedback

💻 Try Output Quiz