JavaScript10 min read
JavaScript Variable Hoisting
Understand JavaScript hoisting. Learn how var, let, const, and functions are hoisted.
Alex Thompson
Dec 20, 2025
28.3k991
JavaScript Hoisting
What is Hoisting?
Hoisting moves declarations to the top of scope.
console.log(x); // undefined (not error!)
var x = 5;
JavaScript sees it as:
var x;
console.log(x);
x = 5;
let/const Hoisting
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