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
beginner
How does hoisting affect variable declarations with
var?Variables declared with
var are hoisted and initialized with undefined, so you can use them before their declaration without a ReferenceError, but their value will be undefined until assigned.Click to reveal answer
intermediate
Are
let and const variables hoisted in JavaScript?Yes,
let and const declarations are hoisted but not initialized. Accessing them before declaration causes a ReferenceError due to the 'temporal dead zone'.Click to reveal answer
beginner
How are function declarations treated during hoisting?
Function declarations are fully hoisted, meaning the entire function is moved to the top of the scope, so you can call the function before its declaration in the code.
Click to reveal answer
intermediate
What happens if you try to use a function expression before it is defined?
Function expressions assigned to variables are hoisted only as variable declarations (with
var hoisted as undefined). Calling the function before assignment results in an error because the variable is not yet a function.Click to reveal answer
What does hoisting do in JavaScript?
✗ Incorrect
Hoisting moves variable and function declarations to the top of their scope before the code runs.
What value does a
var variable have if accessed before its declaration?✗ Incorrect
var variables are hoisted and initialized with undefined.What happens if you access a
let variable before its declaration?✗ Incorrect
let variables are hoisted but not initialized, causing a ReferenceError if accessed early.Can you call a function declared with
function keyword before its declaration?✗ Incorrect
Function declarations are fully hoisted, so you can call them before their code line.
What happens if you call a function expression assigned to a
var variable before assignment?✗ Incorrect
The variable is hoisted as undefined, so calling it as a function causes a TypeError.
Explain hoisting in JavaScript and how it affects variables declared with
var, let, and const.Think about where declarations move before code runs and how accessing variables early behaves.
You got /4 concepts.
Describe the difference between hoisting of function declarations and function expressions.
Consider how the entire function or just the variable name moves up.
You got /4 concepts.