Interactive JavaScript interview practice
Execution Context Interview Lab
Practice real JavaScript interview questions with the DeepJS execution visualizer. Predict the output first, then trace exactly how the result is produced.
- Solve this question
Why does the local variable log undefined?
Declaration instantiation
A var declaration inside a function creates a local binding before its assignment is evaluated.
- Solve this question
What happens when a parameter and a local var share a name?
Lexical scope
A var declaration that names an existing parameter does not create a new binding — it reuses the parameter's binding.
- Solve this question
Does a function read variables from its caller, or from where it was defined?
Lexical scope
JavaScript uses lexical (static) scoping, so a function's scope chain is fixed by where it is written, not by who calls it.
- Solve this question
Can global code read a variable declared inside a function?
Lexical scope
A function-local var binding is not visible from the outer global environment.
- Solve this question
Why is x initially a function and later a number?
Declaration instantiation
Declaration instantiation creates one binding, then later assignments replace the value stored in it.
- Solve this question
Why does var escape the if block?
Declaration instantiation
var is scoped to a function or script, not to an if block.
- Solve this question
When can an undeclared assignment create a global?
Global bindings
Sloppy script assignment to an unresolvable name can create a property on the global object.
- Solve this question
Which assignments affect parameters, locals, and globals?
Lexical scope
The parameter a and local b shadow globals, while c resolves to the outer binding.
- Solve this question
How can a function binding become a number?
Function calls
The function declaration initializes a, then the var initializer overwrites that same binding with 2.
- Solve this question
Does changing a parameter change the outer primitive?
Function calls
The parameter receives a copy of the number value, stored in a separate function binding.
- Solve this question
How does a closure preserve changing state?
Closures
The returned function keeps access to fn’s n binding after fn has returned.
- Solve this question
Why do all three setTimeout callbacks log 3, not 0, 1, 2?
Closures
var creates one shared binding for the whole loop, so every callback closes over the same final value.
- Solve this question
Why does swapping var for let fix the setTimeout loop?
Closures
let creates a fresh binding for i on every iteration, so each callback closes over its own private value.
- Solve this question
Can an IIFE fix the setTimeout loop without using let?
Closures
Calling an immediately invoked function with i as its argument gives each iteration its own parameter binding.