Bird
Raised Fist0
Javascriptprogramming~20 mins

What execution context is in Javascript - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Execution Context Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding Execution Context in JavaScript

What does the term execution context mean in JavaScript?

AIt is the environment where JavaScript code is evaluated and executed.
BIt is a special function that runs before any other code.
CIt is the object that stores all variables globally.
DIt is the browser tab where JavaScript runs.
Attempts:
2 left
💡 Hint

Think about where the code runs and what information it needs to run.

❓ Predict Output
intermediate
2:00remaining
Output of code with nested execution contexts

What is the output of this JavaScript code?

Javascript
function outer() {
  let a = 10;
  function inner() {
    let a = 20;
    console.log(a);
  }
  inner();
  console.log(a);
}
outer();
Aundefined\n10
B10\n20
C20\n10
D20\n20
Attempts:
2 left
💡 Hint

Remember each function has its own execution context with its own variables.

❓ Predict Output
advanced
2:00remaining
Value of variable after execution contexts

What will be the value of result after running this code?

Javascript
var x = 5;
function test() {
  var x = 10;
  if (true) {
    let x = 20;
  }
  return x;
}
var result = test();
A5
B10
C20
Dundefined
Attempts:
2 left
💡 Hint

Look at the scope of each x and which one is returned.

🧠 Conceptual
advanced
2:00remaining
Execution Context and the Call Stack

Which statement best describes the relationship between execution context and the call stack in JavaScript?

AExecution contexts are stored in the heap, not the call stack.
BThe call stack stores all variables and functions globally.
CThe call stack is used only for asynchronous code execution.
DThe call stack keeps track of execution contexts in the order they are created and destroyed.
Attempts:
2 left
💡 Hint

Think about how JavaScript manages running multiple functions.

❓ Predict Output
expert
2:00remaining
Output involving execution context and hoisting

What is the output of this JavaScript code?

Javascript
console.log(a);
var a = 10;
function foo() {
  console.log(a);
  var a = 20;
  console.log(a);
}
foo();
console.log(a);
Aundefined\nundefined\n20\n10
Bundefined\n10\n20\n10
C10\nundefined\n20\n10
DReferenceError\nundefined\n20\n10
Attempts:
2 left
💡 Hint

Remember how var variables are hoisted and initialized as undefined.

Practice

(1/5)
1. What is an execution context in JavaScript?
easy
A. The environment where JavaScript code runs and variables/functions are accessible
B. A special type of variable that stores data temporarily
C. A function that executes automatically when the page loads
D. A tool used to debug JavaScript code in the browser

Solution

  1. Step 1: Understand the meaning of execution context

    Execution context is the environment where JavaScript code runs, controlling variable and function access.
  2. Step 2: Compare options with the definition

    Only The environment where JavaScript code runs and variables/functions are accessible correctly describes this environment; others describe unrelated concepts.
  3. Final Answer:

    The environment where JavaScript code runs and variables/functions are accessible -> Option A
  4. Quick Check:

    Execution context = environment for code execution [OK]
Hint: Execution context = where code runs and variables live [OK]
Common Mistakes:
  • Confusing execution context with variables
  • Thinking it's a debugging tool
  • Mixing it up with functions
2. Which of the following is a valid type of execution context in JavaScript?
easy
A. Global, Function, and Block execution contexts
B. Local, Remote, and Server execution contexts
C. Compile-time, Run-time, and Debug execution contexts
D. Synchronous, Asynchronous, and Parallel execution contexts

Solution

  1. Step 1: Recall the types of execution contexts

    JavaScript has three main execution contexts: Global, Function, and Block.
  2. Step 2: Match options with known types

    Only Global, Function, and Block execution contexts lists the correct types; others list unrelated or incorrect terms.
  3. Final Answer:

    Global, Function, and Block execution contexts -> Option A
  4. Quick Check:

    Execution context types = Global, Function, Block [OK]
Hint: Remember the three main contexts: Global, Function, Block [OK]
Common Mistakes:
  • Confusing execution context types with networking terms
  • Mixing compile/run-time concepts
  • Thinking async types are execution contexts
3. Consider the code:
let x = 10;
function foo() {
  let y = 20;
  console.log(x + y);
}
foo();

Which execution context is active when console.log runs?
medium
A. Global execution context only
B. Function execution context of foo
C. Block execution context inside foo
D. No execution context is active

Solution

  1. Step 1: Identify where console.log is called

    It is inside the function foo, so the function's execution context is active.
  2. Step 2: Understand execution context hierarchy

    When foo runs, its function execution context is created and active during console.log.
  3. Final Answer:

    Function execution context of foo -> Option B
  4. Quick Check:

    Inside function = function execution context active [OK]
Hint: Code inside function runs in function execution context [OK]
Common Mistakes:
  • Thinking only global context is active
  • Confusing block context with function context
  • Believing no context is active during execution
4. Find the error in this code related to execution context:
function test() {
  console.log(a);
  let a = 5;
}
test();
medium
A. SyntaxError due to missing semicolon
B. No error, outputs 5
C. ReferenceError because a is used before declaration
D. TypeError because a is not a function

Solution

  1. Step 1: Analyze variable declaration and usage

    a is declared with let after it is logged, so it is in the temporal dead zone.
  2. Step 2: Understand execution context and hoisting

    let variables are not hoisted like var, causing a ReferenceError when accessed before declaration.
  3. Final Answer:

    ReferenceError because a is used before declaration -> Option C
  4. Quick Check:

    Accessing let before declaration = ReferenceError [OK]
Hint: Accessing let/const before declaration causes ReferenceError [OK]
Common Mistakes:
  • Thinking it outputs undefined
  • Confusing with var hoisting
  • Ignoring temporal dead zone
5. You want to create a block execution context to limit variable scope inside an if statement. Which code correctly creates a block execution context?
hard
A.
let x = 10;
console.log(x);
B.
function test() {
  var x = 10;
  console.log(x);
}
C.
if (true)
  var x = 10;
console.log(x);
D.
if (true) {
  let x = 10;
  console.log(x);
}

Solution

  1. Step 1: Identify block execution context creation

    Block execution context is created by blocks like { ... } with let or const variables.
  2. Step 2: Check each option for block scope

    if (true) {
      let x = 10;
      console.log(x);
    }
    uses let inside an if block, creating a block execution context. Others use function or global scope.
  3. Final Answer:

    if (true) { let x = 10; console.log(x); } -> Option D
  4. Quick Check:

    Block scope needs { } and let/const [OK]
Hint: Use { } with let/const to create block execution context [OK]
Common Mistakes:
  • Using var inside if block expecting block scope
  • Not using braces for block
  • Confusing function scope with block scope
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard