Hoisting in JavaScript
Hoisting is JavaScript's behavior of moving variable and function declarations to the top of their scope during compilation – before code execution.
This means you can use functions and var variables before declaring them in code, but there are important differences with let/const.
Function Declaration Hoisting
Function declarations are fully hoisted – you can call them before defining.
var Hoisting
var declarations are hoisted, but initializations are not – the variable is undefined until assigned.
let and const – No Hoisting (Temporal Dead Zone)
let and const are NOT hoisted in the same way – accessing them before declaration causes ReferenceError (Temporal Dead Zone).
Function Expressions and Hoisting
Function expressions (including arrows) are not hoisted like declarations.
Best Practices
- Always declare variables at the top of their scope.
- Prefer let/const over var.
- Use function declarations when order doesn't matter; expressions for conditional logic.
Quick Quiz
We have reviewed and checked the materials, but errors may still occur. The content is provided for educational purposes only, so use it at your own responsibility and verify with other sources if needed.
✨ Ask Lara — your AI study partner
Unlock personalized learning support. Lara can explain lessons, summarize topics, and answer your study questions — available from the Go plan and above.
Lara helps you learn faster — exclusive to ReadyTools Go, Plus, and Max members.

