JavaScript Hoisting
Hoisting means JavaScript sets up some names before your code runs line by line.
It is like putting name tags on seats before the show starts.
Different kinds of variables get different setup rules.
What hoisting means
How var behaves
How let and const behave
How functions behave
The big idea
Before running, JavaScript scans for declarations.
Some names are ready early.
Their values may still be empty until the real line runs.
var is lifted with undefined
With var, the name exists early.
Until assignment, the value is undefined.
That can hide mistakes if you use the name too soon.
let and const sit in a waiting zone
let and const are also known early.
But you cannot use them before their line.
That waiting zone is called the temporal dead zone.
Function declarations
A full function declaration can be called before its line.
JavaScript already knows the whole function.
That feels like the recipe card was ready from the start.
Function expressions are different
A function stored in a variable follows variable rules.
If you use const or let, wait until after the line.
Tip: Declare names before you use them. Hoisting is handy to understand, but clear order is easier to read.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.