Hoisting is one of those topics that feels magical until you see the rules clearly.
Quick summary
var— declared variables are hoisted and initialized asundefined. Using them before the assignment line does not throw; you just getundefined.let/const— also hoisted, but they stay in the temporal dead zone until initialization. Accessing them early throws aReferenceError.- Function declarations — fully hoisted. You can call them before their line in the file.
- Function expressions and arrow functions — follow variable rules. You cannot call them before the assignment.
Practical rule
Declare and initialize before you use. Prefer const / let, and treat hoisting as something to understand — not something to rely on for clever code.
That mindset alone prevents a whole class of bugs and interview footguns.