Question 08 / 31

Which assignments affect parameters, locals, and globals?

Topic: Lexical scopeDifficulty: Intermediate

The parameter a and local b shadow globals, while c resolves to the outer binding.

Solve it with the execution visualizerStep through every binding, function call, and console output below.

Predict the output

After fn returns, determine which of the three global values changed.

var a = 12, b = 13, c = 14
function fn(a) {
  a = 0
  var b = 0
  c = 0
}
fn(a)
console.log(a)
console.log(b)
console.log(c)
Reveal the answer and explanation

Expected output

12
13
0

Why this happens

The parameter a is a local binding initialized from the argument value 12. Assigning 0 to it does not modify global a.

The var declaration creates a local b, so b = 0 also leaves global b unchanged.

There is no local c. Name resolution reaches the global c binding, so c = 0 changes the value observed after the call.

What this question tests

  • parameter bindings
  • local shadowing
  • scope-chain writes

Runtime assumptions

The example passes a primitive number; no shared object mutation is involved.

Specification references

JavaScript Code EditorDirectly edit or paste custom code
Step 0 of 0
←→StepSpaceRun
Press → (Step) or Space (Run)
Phase 1: Compilation(Hoisting & Memory Setup)
➔
Phase 2: Execution(Line-by-line Evaluation)
Execution Step Breakdown

Press "→" / click "▶" to step line-by-line, or press "Space" / click "▶ Run" for auto-play.