02 / 08

List the types of Execution Context in JS.

Global Execution Context/GEC, Functional Execution Context/FEC, Eval Execution Context

  1. 1

    Global Execution Context/GEC

  2. 2

    Functional Execution Context/FEC

  3. 3

    Eval Execution Context

Difficulty: 3/10
Topics: execution context types, scope chain, module loading

Scenario Questions

0-2 years experience
  1. 1

    If you write a script that declares a variable and a function, where does each piece of code execute and what execution context is created?

  2. 2

    What execution context is created when you call eval inside a function, and how does it affect variable scope?

  3. 3

    When you add a <script> tag to an HTML page, which execution context does that code run in?

2-5 years experience
  1. 1

    We have a bug where a variable defined in an ES module is undefined when accessed from another module. How could the different execution contexts be causing this issue?

  2. 2

    During a refactor you moved some code from the global scope into a function and a variable suddenly became undefined. Explain how the scope chain and execution context changed.

  3. 3

    You notice that using eval inside a callback is causing a slowdown. Explain the execution context created by eval and why it might be problematic.

5-8 years experience
  1. 1

    Our SPA loads third‑party scripts that use eval and also uses ES modules. How would you order the loading and manage execution contexts to avoid leaking variables and ensure the correct this binding?

  2. 2

    Design a module loader that isolates each module's execution context while still allowing shared utilities. What trade‑offs do you consider between using the global context versus module contexts?

  3. 3

    When profiling a large application you see many execution contexts being created during navigation. How would you reduce the overhead and what impact does the type of context have on memory usage?

8+ years experience
  1. 1

    We are migrating a legacy codebase that heavily relies on the global execution context to an ES‑module architecture. What strategy would you propose to transition safely, handling differences in execution context, scope, and this binding across multiple teams?

  2. 2

    In a micro‑frontend architecture each team ships a bundle that may run in its own execution context. How would you define conventions or tooling to manage context isolation and avoid conflicts at the organization level?

Follow-up Questions

  • Can you walk me through what the engine does when it enters a function execution context?
  • How is the this value determined in each type of execution context?
  • What are the security or performance implications of using eval compared to other contexts?