JavaScript
JavaScript HoistingJavaScript Hoisting
JavaScript hoisting moves variable and function declarations to the top.
Read Time
5 min readDifficulty
BeginnerLast Updated
Jun 15, 2026Version
v1.0.0Introduction
JavaScript secretly moves all variable and function declarations to the very top of the script before running the code. Because of this strange behavior, developers can call a function on line 1 even if the function isn't written until line 50.
Example
Example
Key Points
- Hoisting moves declarations, not assignments.
- `var` declarations hoist and initialize as undefined.
- `let` and `const` declarations hoist but do not initialize.
- Calling functions before they are written works perfectly.