JavaScript Execution Context Quiz

JavaScript
0 Passed
0% acceptance

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.

40 Questions
~80 minutes
1

Question 1

What does the term "execution context" describe in JavaScript?

A
The conceptual environment in which code is evaluated and executed
B
A DOM node that wraps script tags
C
A compiled binary produced by V8
D
A CSS layout mode
2

Question 2

What is logged by this script?

javascript
console.log('start')
function reportPhase() {
  console.log('function body')
}
reportPhase()
console.log('end')
A
start → function body → end
B
function body → start → end
C
start → end → function body
D
Only start because execution stops
3

Question 3

Which phases does every execution context move through?

A
Creation phase followed by execution phase
B
Compilation phase followed by garbage phase
C
Layout phase followed by paint phase
D
Networking phase followed by rendering phase
4

Question 4

What does this program output?

javascript
const scopeLabel = 'global'
function displayScope() {
  console.log(scopeLabel)
}
displayScope()
A
global
B
undefined
C
Throws ReferenceError
D
function displayScope
5

Question 5

When is the global execution context created?

A
Before any code runs, as soon as the engine loads a script
B
After the first function is invoked
C
Only after DOMContentLoaded fires
D
Only when a module exports something
6

Question 6

Which statement best describes the relationship between the global execution context and globalThis?

A
Global variables declared with var become properties on globalThis in non-module scripts
B
globalThis points to the DOM body element
C
globalThis is only defined in Node.js
D
globalThis always equals undefined
7

Question 7

What happens when this code runs in a non-strict script?

javascript
console.log(color)
var color = 'blue'
A
It logs undefined because the declaration is hoisted during the creation phase
B
It logs blue because assignments hoist with values
C
It throws ReferenceError because var is block scoped
D
It logs null because uninitialized globals default to null
8

Question 8

Why is it recommended to keep the global execution context lightweight?

A
Because everything stored there lives for the lifetime of the page or process and can clog memory
B
Because global contexts execute in parallel threads
C
Because global contexts cannot access the DOM
D
Because the global context cannot reference functions
9

Question 9

What logs here?

javascript
function init() {
  console.log(typeof helper)
  function helper() {}
}
init()
A
function
B
undefined
C
Throws ReferenceError
D
null
10

Question 10

Which data lives inside a function execution context?

A
Arguments object, parameter values, local bindings, outer lexical reference, and the this binding
B
Only global variables
C
Only DOM nodes
D
GPU buffers
11

Question 11

When is a new function execution context pushed onto the call stack?

A
Whenever the function is invoked (called) regardless of how it was defined
B
When the function is declared
C
Only when the function returns a value
D
Only when the function is recursive
12

Question 12

What appears in the console?

javascript
function calcTotal(price) {
  console.log(total)
  var total = price * 2
  return total
}
calcTotal(4)
A
undefined, then the function returns 8
B
ReferenceError
C
0
D
null
13

Question 13

Which tasks happen during the creation phase of a function execution context?

A
Arguments object creation, parameter initialization, hoisting of declarations, and linking to outer lexical environment
B
Running every console.log in the function body
C
Fetching remote modules
D
Rendering the DOM tree
14

Question 14

How does the execution phase differ from the creation phase?

A
Execution phase runs the code line by line, assigning and mutating values that were set up during creation
B
Execution phase determines the this binding
C
Creation phase runs console.log statements
D
Execution phase builds the arguments object
15

Question 15

What prints in this closure example?

javascript
function outer() {
  const label = 'outer scope'
  return function inner() {
    console.log(label)
  }
}
const fn = outer()
fn()
A
outer scope
B
undefined
C
Throws ReferenceError
D
inner
16

Question 16

What does the arguments object capture inside a function context?

A
Array-like access to all arguments provided, even if they lack named parameters
B
Only default parameter values
C
DOM event objects
D
Global variables
17

Question 17

What is logged?

javascript
const region = 'global'
function layerOne() {
  const region = 'layerOne'
  function layerTwo() {
    console.log(region)
  }
  layerTwo()
}
layerOne()
A
layerOne
B
global
C
undefined
D
Throws ReferenceError
18

Question 18

How do the variable environment and lexical environment differ?

A
Variable environment holds var/function bindings for the current context, while lexical environment keeps track of outer references for identifier resolution
B
They are identical names for the DOM tree
C
Variable environment only exists in modules
D
Lexical environment only stores numbers
19

Question 19

What happens if the engine cannot find an identifier in any lexical environment on the scope chain?

A
A ReferenceError is thrown
B
The engine creates a global variable automatically in strict mode
C
The engine converts the identifier to null
D
The identifier is redefined to 0
20

Question 20

Why can excessively deep nesting hurt performance?

A
Identifier resolution must traverse more lexical environments before succeeding
B
Deep nesting triggers garbage collection continuously
C
Deep nesting disables tail-call optimization by specification
D
Deep nesting prevents closures from forming
21

Question 21

What sequence is logged?

javascript
let message = 'outer'
{
  let message = 'block'
  console.log(message)
}
console.log(message)
A
block then outer
B
outer then block
C
block twice
D
ReferenceError twice
22

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?

A
Lexical (static) scoping
B
Dynamic scoping
C
Temporal scoping
D
Event scoping
23

Question 23

How does JavaScript build the scope chain for a function?

A
It stores a reference to the lexical environment where the function was created, then walks outward as needed
B
It inspects runtime call stack to guess which variables to use
C
It serializes the DOM tree into memory
D
It evaluates every module at once
24

Question 24

What occurs when this code executes?

javascript
console.log(total)
let total = 5
A
ReferenceError due to the temporal dead zone
B
Logs undefined like var hoisting
C
Logs 5
D
Logs null
25

Question 25

Under default binding rules (non-strict), what does this reference inside a standalone function call?

A
The global object
B
undefined
C
The function’s prototype object
D
Whatever object was passed as the first argument
26

Question 26

How is this determined during method invocation?

A
It refers to the object placed before the dot (or bracket) at call time
B
It always refers to the global object
C
It is permanently bound to the prototype
D
It points to the arguments object
27

Question 27

What does this log?

javascript
const counter = {
  count: 0,
  increment() {
    this.count += 1
    return this.count
  }
}
console.log(counter.increment())
A
1
B
0
C
undefined
D
Throws ReferenceError
28

Question 28

How do arrow functions determine this?

A
They capture the lexical this from their defining scope and never create their own
B
They always bind to the global object
C
They prompt the user for a binding
D
They behave like constructors
29

Question 29

Which method allows you to explicitly set this for a single invocation while providing arguments individually?

A
Function.prototype.call
B
Function.prototype.apply
C
Function.prototype.bind
D
Object.create
30

Question 30

What does Function.prototype.bind return?

A
A new function permanently bound to the provided this value and optional leading arguments
B
The original function without changes
C
A boolean
D
An immediately invoked function expression
31

Question 31

What is the call stack?

A
A LIFO structure the engine uses to track active execution contexts
B
A queue for pending network requests
C
A list of DOM mutations awaiting paint
D
A data structure only used in CSS
32

Question 32

When does the engine pop an execution context off the call stack?

A
After the function finishes executing and control returns to its caller
B
Immediately after the function is declared
C
As soon as setTimeout is scheduled
D
Before the function’s return statement runs
33

Question 33

What order is logged?

javascript
function third() {
  console.log('third')
}
function second() {
  third()
  console.log('second')
}
function first() {
  second()
  console.log('first')
}
first()
console.log('global done')
A
third → second → first → global done
B
first → second → third → global done
C
third → first → second → global done
D
global done → third → second → first
34

Question 34

What is a stack overflow in JavaScript?

A
When too many execution contexts accumulate without unwinding, exhausting the engine’s stack size
B
When the DOM has too many elements
C
When a promise rejects
D
When CSS specificity ties
35

Question 35

Why do asynchronous callbacks wait even if they are scheduled immediately?

A
Because the event loop cannot place callbacks onto the call stack until it is empty
B
Because async callbacks skip the call stack entirely
C
Because setTimeout blocks the call stack
D
Because callbacks require user permission
36

Question 36

What does this recursion log?

javascript
function countdown(n) {
  if (n === 0) {
    console.log('done')
    return
  }
  console.log(n)
  countdown(n - 1)
}
countdown(3)
A
3 → 2 → 1 → done
B
done → 1 → 2 → 3
C
3 → done
D
Throws ReferenceError
37

Question 37

How do stack traces in errors relate to execution contexts?

A
They list the sequence of active or recently unwound execution contexts when the error occurred
B
They show the DOM tree at crash time
C
They show network waterfall timing
D
They list CSS selectors currently applied
38

Question 38

What role does the microtask queue (e.g., promises) play relative to the call stack?

A
Microtasks run after the current call stack empties but before the next macrotask
B
Microtasks preempt synchronous functions mid-execution
C
Microtasks live on the same stack frame forever
D
Microtasks only exist in CSS animations
39

Question 39

Why is it valuable to keep call stack depth shallow in synchronous code?

A
Shallow stacks reduce the chance of overflow and make debugging easier
B
The engine refuses to run code if the stack has fewer than five frames
C
Shallow stacks disable garbage collection
D
Stack depth controls CSS specificity
40

Question 40

How can developer tools assist in inspecting execution contexts?

A
Breakpoints stop execution so you can view the call stack, scope chain, and variable bindings for the paused context
B
They automatically refactor code to remove recursion
C
They change the this binding permanently
D
They disable asynchronous callbacks

QUIZZES IN JavaScript