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.

31 of 31 questions
  1. 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
  2. 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
  3. 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
  4. 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
  5. 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
  6. 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
  7. 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
  8. 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
  9. 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
  10. 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
  11. 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
  12. 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
  13. 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
  14. 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
  15. 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
  16. 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
  17. 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
  18. 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
  19. 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
  20. 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
  21. 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
  22. 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
  23. 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
  24. 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
  25. 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
  26. 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
  27. 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
  28. 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
  29. 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
  30. 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
  31. 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.

    Solve this question