🟢 EasyClosures & Scope💻 Output Question

let in loop closure (fix)

💡

Hint

let creates a new variable per iteration — each closure gets its own copy.

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 is block-scoped. Each loop iteration creates a NEW binding of i. Each closure captures its own unique i.

Key Insight: let creates a new variable per iteration — each closure gets its own copy.

More Closures & Scope Output Questions

🟢 EasyClassic var in loop closure🟡 MediumClosure counter🟡 MediumIIFE closure🔴 HardClosure variable lookup

Practice predicting output live →

66 output questions with instant feedback

💻 Try Output Quiz