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 instantiationFoundation
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 scopeFoundation
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 scopeIntermediate
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 scopeFoundation
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 instantiationIntermediate
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 instantiationFoundation
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 bindingsIntermediate
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 scopeIntermediate
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 callsIntermediate
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 callsFoundation
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?
ClosuresIntermediate
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?
ClosuresAdvanced
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?
ClosuresAdvanced
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?
ClosuresAdvanced
Calling an immediately invoked function with i as its argument gives each iteration its own parameter binding.
- Solve this question
Does a same-named local variable shadow this.message?
this bindingFoundation
A local variable and a property read through this live in entirely separate namespaces.
- Solve this question
What happens to this when a method is passed to setTimeout?
this bindingFoundation
Passing object.method as a bare function reference detaches it from its receiver.
- Solve this question
Why does calling the same function two ways log two different values?
this bindingFoundation
this is determined entirely by the call-site syntax, not by where the function was defined.
- Solve this question
Why does the arrow-function property fail to read the object?
this bindingIntermediate
Unlike a shorthand method, an arrow function never binds its own this to the object that holds it.
- Solve this question
Why does the last line print nothing?
this bindingIntermediate
call and apply invoke the function immediately with a supplied this; bind only returns a new function.
- Solve this question
Does passing obj.foo into another function carry obj along with it?
this bindingIntermediate
A function argument is just a value — its original receiver is never part of that value.
- Solve this question
Why does the destructured getName still know the instance?
this bindingAdvanced
An arrow function created inside a constructor permanently captures that constructor call's this.
- Solve this question
How does filter's second argument change this inside the callback?
this bindingIntermediate
Several array iteration methods accept an optional thisArg that overrides the callback's this.
- Solve this question
Does .call() at the end of a chain bind the outer call or just the inner one?
this bindingAdvanced
call attaches only to the specific function value it is invoked on, immediately before that invocation.
- Solve this question
How do a captured closure variable and this evolve independently here?
ClosuresAdvanced
The IIFE's parameter num is captured by closure, while every this is re-resolved fresh at each call site — including for the global num binding itself.
- Solve this question
Why does calling arguments[0]() read this.length as 3?
this bindingAdvanced
Calling a value through a member expression binds this to whatever object that expression was read off — even the current call's own arguments object.
- Solve this question
Why do these logs run immediately instead of after the delay?
this bindingAdvanced
Function arguments are evaluated before the call that receives them runs — so a `.call()` written as an argument executes right away, not later.
- Solve this question
Does grouping a member expression in parentheses change what this is?
this bindingIntermediate
Parentheses around a property reference don't strip it — this is still bound the same way as calling the property directly.
- Solve this question
Which of these four this flavors can .call() actually override?
this bindingAdvanced
An ordinary method, an object-literal arrow, and two functions-that-return-functions each resolve this differently — and one of the four never even reaches a console.log.
- Solve this question
Do constructor-assigned methods still follow the call site?
this bindingAdvanced
Assigning this.foo = function(){...} inside a constructor changes where the function lives, not how its own this gets resolved later — the call-site rule still runs the show.
- Solve this question
Does nesting an object one level deeper change how this resolves?
this bindingAdvanced
A method reached through person1.obj.foo1() still resolves this from the call site — the extra layer of property access does not add a receiver of its own.
- Solve this question
When every this rule applies at once, which one wins?
this bindingAdvanced
Default, implicit, and all three explicit forms — call, apply, and bind — plus new and an arrow, chained together so each rule's override of the last one is visible in a single trace.