JavaScript Execution Context Quiz
Dive into 40 questions covering how JavaScript builds global and function execution contexts, creation and execution phases, lexical and variable environments, scope chains, hoisting, this binding, and call stack behavior.
Question 1
What does the term "execution context" describe in JavaScript?
Question 2
What is logged by this script?
console.log('start')
function reportPhase() {
console.log('function body')
}
reportPhase()
console.log('end')Question 3
Which phases does every execution context move through?
Question 4
What does this program output?
const scopeLabel = 'global'
function displayScope() {
console.log(scopeLabel)
}
displayScope()Question 5
When is the global execution context created?
Question 6
Which statement best describes the relationship between the global execution context and globalThis?
Question 7
What happens when this code runs in a non-strict script?
console.log(color)
var color = 'blue'Question 8
Why is it recommended to keep the global execution context lightweight?
Question 9
What logs here?
function init() {
console.log(typeof helper)
function helper() {}
}
init()Question 10
Which data lives inside a function execution context?
Question 11
When is a new function execution context pushed onto the call stack?
Question 12
What appears in the console?
function calcTotal(price) {
console.log(total)
var total = price * 2
return total
}
calcTotal(4)Question 13
Which tasks happen during the creation phase of a function execution context?
Question 14
How does the execution phase differ from the creation phase?
Question 15
What prints in this closure example?
function outer() {
const label = 'outer scope'
return function inner() {
console.log(label)
}
}
const fn = outer()
fn()Question 16
What does the arguments object capture inside a function context?
Question 17
What is logged?
const region = 'global'
function layerOne() {
const region = 'layerOne'
function layerTwo() {
console.log(region)
}
layerTwo()
}
layerOne()Question 18
How do the variable environment and lexical environment differ?
Question 19
What happens if the engine cannot find an identifier in any lexical environment on the scope chain?
Question 20
Why can excessively deep nesting hurt performance?
Question 21
What sequence is logged?
let message = 'outer'
{
let message = 'block'
console.log(message)
}
console.log(message)Question 22
What term describes the fact that a function’s accessible scopes are determined by where it was declared, not where it is called?
Question 23
How does JavaScript build the scope chain for a function?
Question 24
What occurs when this code executes?
console.log(total)
let total = 5Question 25
Under default binding rules (non-strict), what does this reference inside a standalone function call?
Question 26
How is this determined during method invocation?
Question 27
What does this log?
const counter = {
count: 0,
increment() {
this.count += 1
return this.count
}
}
console.log(counter.increment())Question 28
How do arrow functions determine this?
Question 29
Which method allows you to explicitly set this for a single invocation while providing arguments individually?
Question 30
What does Function.prototype.bind return?
Question 31
What is the call stack?
Question 32
When does the engine pop an execution context off the call stack?
Question 33
What order is logged?
function third() {
console.log('third')
}
function second() {
third()
console.log('second')
}
function first() {
second()
console.log('first')
}
first()
console.log('global done')Question 34
What is a stack overflow in JavaScript?
Question 35
Why do asynchronous callbacks wait even if they are scheduled immediately?
Question 36
What does this recursion log?
function countdown(n) {
if (n === 0) {
console.log('done')
return
}
console.log(n)
countdown(n - 1)
}
countdown(3)Question 37
How do stack traces in errors relate to execution contexts?
Question 38
What role does the microtask queue (e.g., promises) play relative to the call stack?
Question 39
Why is it valuable to keep call stack depth shallow in synchronous code?
Question 40
How can developer tools assist in inspecting execution contexts?
