🟡 MediumClosures & Scope💻 Output Question

Scope chain lookup

💡

Hint

Scope chain: inner function looks up through all enclosing scopes until global.

What does this output?

let a = 1;

function outer() {
  let b = 2;
  function inner() {
    let c = 3;
    console.log(a, b, c);
  }
  inner();
}

outer();

Correct Output

1 2 3

Why this output?

Explanation: inner can access c (own scope), b (outer's scope via closure), and a (global via scope chain). JS walks up the scope chain until it finds the variable.

Key Insight: Scope chain: inner function looks up through all enclosing scopes until global.

More Closures & Scope Output Questions

🟢 EasyClassic var in loop closure→🟢 Easylet in loop closure (fix)→🟡 MediumClosure counter→🟡 MediumIIFE closure→

Practice predicting output live →

66 output questions with instant feedback

💻 Try Output Quiz