JavaScript8 min read
JavaScript Variable Hoisting
Understand JavaScript hoisting. Learn how var, let, const, and functions are hoisted.
Alex Thompson
December 19, 2025
0.0k0
JavaScript Hoisting
What is Hoisting?
Hoisting moves declarations to the top of scope.
```javascript console.log(x); // undefined (not error!) var x = 5; ```
**JavaScript sees it as:** ```javascript var x; console.log(x); x = 5; ```
let/const Hoisting
```javascript console.log(x); // Error! (Temporal Dead Zone) let x = 5; ```
**let/const are hoisted but not initialized.**
Key Takeaway
var hoists and initializes. let/const hoist but not initialize. Always declare before use.
#JavaScript#Hoisting#Scope#Intermediate