MediumClosures & Scope💻 Output Question

Closure captures binding not snapshot

💡

Hint

Closures capture variable bindings (references), not values. The latest assignment is always visible.

What does this output?

let value = 1;
const fn = () => value;
value = 2;
console.log(fn());
value = 3;
console.log(fn());

Correct Output

2
3

Why this output?

Explanation: fn closes over the variable value, not the value 1 at definition time. It always reads the current value of the binding.

Key Insight: Closures capture variable bindings (references), not values. The latest assignment is always visible.

More Closures & Scope Output Questions

EasyClassic var in loop with setTimeoutEasylet in loop — each iteration gets own bindingMediumIIFE captures loop variableMediumClosure mutation persists across calls

Practice predicting output live →

66 output questions with instant feedback

💻 Try Output Quiz