Question 08 / 14
Which assignments affect parameters, locals, and globals?
Topic: Lexical scope
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
0Why 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.