Skip to content
2 min read
Mastering JavaScript

How JavaScript hoisting actually works

Hoisting is one of those topics that feels magical until you see the rules clearly.

Quick summary

  • var — declared variables are hoisted and initialized as undefined. Using them before the assignment line does not throw; you just get undefined.
  • let / const — also hoisted, but they stay in the temporal dead zone until initialization. Accessing them early throws a ReferenceError.
  • 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.

Open on Instagram