Recall & Review
beginner
What is hoisting in JavaScript?
Hoisting is JavaScript's behavior of moving variable and function declarations to the top of their containing scope before code execution.
Click to reveal answer
intermediate
How does hoisting behave differently with
let and const compared to var?let and const are hoisted but not initialized. They stay in a 'temporal dead zone' until their declaration line, causing a ReferenceError if accessed earlier. var is hoisted and initialized with undefined.Click to reveal answer
beginner
What happens if you try to access a
let variable before its declaration?You get a ReferenceError because the variable is in the temporal dead zone until its declaration is reached.
Click to reveal answer
beginner
Can you reassign a
const variable after declaration?No,
const variables cannot be reassigned after they are initialized. Trying to do so causes a TypeError.Click to reveal answer
intermediate
Explain the 'temporal dead zone' in simple terms.
The temporal dead zone is the time between entering a scope and when a
let or const variable is declared. During this time, the variable exists but cannot be accessed.Click to reveal answer
What will happen if you run this code?<br>
console.log(x);<br>let x = 5;
✗ Incorrect
Accessing
let variable x before declaration causes a ReferenceError due to the temporal dead zone.Which statement is true about
const variables?✗ Incorrect
const variables are hoisted but not initialized, so accessing them before declaration causes a ReferenceError.What is the temporal dead zone?
✗ Incorrect
The temporal dead zone is the period after entering a scope but before
let or const variables are declared.What will this code output?<br>
var a = 1;<br>console.log(a);<br>var a = 2;<br>console.log(a);
✗ Incorrect
var variables are hoisted and initialized with undefined, but here a is assigned 1 before first log, so outputs 1 then 2.Which keyword allows hoisting with initialization to undefined?
✗ Incorrect
var declarations are hoisted and initialized with undefined, unlike let and const.Describe how hoisting works differently for
var, let, and const variables.Think about when variables become usable in the code.
You got /4 concepts.
Explain the concept of the temporal dead zone and why it matters when using
let and const.Consider what happens if you try to use a variable too early.
You got /4 concepts.