MediumClosures & Scope💻 Output Question

Closure mutation persists across calls

💡

Hint

Closures share a live variable binding. Mutations persist and are visible on every subsequent call.

What does this output?

function outer() {
  let x = 10;
  return function inner() {
    x++;
    return x;
  };
}
const fn = outer();
console.log(fn());
console.log(fn());
console.log(fn());

Correct Output

11
12
13

Why this output?

Explanation: inner closes over x. Each call increments the same x — closures capture the live variable binding, not a snapshot.

Key Insight: Closures share a live variable binding. Mutations persist and are visible on every subsequent call.

More Closures & Scope Output Questions

EasyClassic var in loop with setTimeoutEasylet in loop — each iteration gets own bindingMediumIIFE captures loop variableEasylet block scope — inner does not leak

Practice predicting output live →

66 output questions with instant feedback

💻 Try Output Quiz