0
0
Javascriptprogramming~20 mins

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

Choose your learning style9 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.