Recall & Review
beginner
What is variable hoisting in JavaScript?
Variable hoisting is JavaScript's behavior of moving variable declarations to the top of their containing scope during the compilation phase, before code execution.
Click to reveal answer
intermediate
How does hoisting differ between
var, let, and const?var declarations are hoisted and initialized with undefined. let and const are hoisted but not initialized, causing a 'temporal dead zone' until their declaration is reached.Click to reveal answer
beginner
What happens if you access a
let variable before its declaration?Accessing a
let variable before its declaration throws a ReferenceError because it is in the temporal dead zone until the declaration line is executed.Click to reveal answer
beginner
Consider this code:<br>
console.log(x); var x = 5;<br>What is the output and why?
The output is
undefined. The declaration var x is hoisted to the top and initialized with undefined, but the assignment = 5 happens after the console.log.Click to reveal answer
intermediate
Does function declaration hoisting behave the same as variable hoisting?
Function declarations are hoisted completely, meaning the entire function body is moved to the top, allowing you to call the function before its declaration in the code.
Click to reveal answer
What will this code output?<br>
console.log(a); let a = 10;
✗ Incorrect
Accessing a
let variable before declaration causes a ReferenceError due to the temporal dead zone.Which keyword's variables are hoisted and initialized with
undefined?✗ Incorrect
var variables are hoisted and initialized with undefined.What is the temporal dead zone?
✗ Incorrect
The temporal dead zone is the period from the start of a scope until a
let or const variable is declared, during which accessing it causes an error.What will this code output?<br>
foo(); function foo() { console.log('Hello'); }✗ Incorrect
Function declarations are hoisted completely, so
foo can be called before its declaration.Which of these is NOT true about
const variables and hoisting?✗ Incorrect
const variables cannot be accessed before declaration; doing so causes a ReferenceError.Explain variable hoisting in JavaScript and how it affects
var, let, and const declarations.Think about when variables become available in the code and what happens if you try to use them too early.
You got /4 concepts.
Describe how function declarations are hoisted and how this differs from variable hoisting.
Consider what happens when you call a function before it appears in the code.
You got /3 concepts.