An execution context is the environment where JavaScript code runs. It holds information like variables, functions, and the value of 'this'.
Click to reveal answer
beginner
Name the three main types of execution contexts in JavaScript.
Global execution context, Function execution context, and Eval execution context.
Click to reveal answer
intermediate
What does the 'this' keyword represent inside an execution context?
'this' refers to the object that is currently executing the code in that context.
Click to reveal answer
intermediate
What happens when a function is called in terms of execution context?
A new function execution context is created and pushed onto the call stack to run the function's code.
Click to reveal answer
intermediate
How does the JavaScript engine manage multiple execution contexts?
It uses a call stack to keep track of execution contexts, running the top one and removing it when done.
Click to reveal answer
What is the first execution context created when JavaScript code runs?
AEval execution context
BFunction execution context
CBlock execution context
DGlobal execution context
✗ Incorrect
The global execution context is created first and represents the outermost environment.
When a function is called, what happens to the execution context?
AThe global context is replaced
BThe function runs without any execution context
CA new execution context is created and added to the call stack
DThe previous context is deleted
✗ Incorrect
Each function call creates a new execution context pushed onto the call stack.
Which of these is NOT part of an execution context?
ACall stack
BLexical environment
C'this' binding
DVariable environment
✗ Incorrect
The call stack manages execution contexts but is not part of a single execution context.
What does the 'this' keyword refer to inside a function execution context?
AThe object that called the function
BThe global object always
CThe function itself
DUndefined
✗ Incorrect
'this' refers to the object that called the function, depending on how the function is called.
What is the role of the call stack in execution contexts?
ATo store variables
BTo keep track of execution contexts in order
CTo execute code asynchronously
DTo manage memory allocation
✗ Incorrect
The call stack tracks which execution context is currently running and manages their order.
Explain what an execution context is and why it is important in JavaScript.
Think about the environment where your code runs.
You got /3 concepts.
Describe how the call stack and execution contexts work together when functions are called.
Imagine stacking plates when you call functions.
You got /3 concepts.
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
Step 1: Understand the meaning of execution context
Execution context is the environment where JavaScript code runs, controlling variable and function access.
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.
Final Answer:
The environment where JavaScript code runs and variables/functions are accessible -> Option A
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
Step 1: Recall the types of execution contexts
JavaScript has three main execution contexts: Global, Function, and Block.
Step 2: Match options with known types
Only Global, Function, and Block execution contexts lists the correct types; others list unrelated or incorrect terms.
Final Answer:
Global, Function, and Block execution contexts -> Option A
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
Step 1: Identify where console.log is called
It is inside the function foo, so the function's execution context is active.
Step 2: Understand execution context hierarchy
When foo runs, its function execution context is created and active during console.log.
Final Answer:
Function execution context of foo -> Option B
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
Step 1: Analyze variable declaration and usage
a is declared with let after it is logged, so it is in the temporal dead zone.
Step 2: Understand execution context and hoisting
let variables are not hoisted like var, causing a ReferenceError when accessed before declaration.
Final Answer:
ReferenceError because a is used before declaration -> Option C
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
Step 1: Identify block execution context creation
Block execution context is created by blocks like { ... } with let or const variables.
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.
Final Answer:
if (true) { let x = 10; console.log(x); } -> Option D
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 unknownstrongwhile earning +1 Grip toward your certificate.