Day 5 of My JavaScript Visual Series 📚✨
💡 Hoisting in JavaScript – JavaScript ka jugaadu nature 😄
Real life example : -
Imagine you’re in class and the teacher asks a question…
You didn’t study, but your bestie already gave your name to answer — JavaScript does the same thing 😅
- It remembers your function or variable declarations even before they are actually written — that’s Hoisting.
🔁 Real-Life in Code:
🔹 Function Hoisting
You can call the function before declaring it.
greet();
function greet() {
console.log("Good to see you!");
}
🔹 Anonymous Function / Arrow Function?
No shortcut! These won’t work if you call them before defining.
sayHi(); // ❌ Error
var sayHi = function() {
console.log("Hey there!");
};
🔹 var?
Hoisted, but value is undefined
console.log(x); // undefined
var x = 10;
🔹 let & const? [Interview Question]
JavaScript: “I know it exists… but you can't touch it yet 😶”
They live in a Temporal Dead Zone (TDZ).
console.log(y); // ❌ ReferenceError
let y = 5;
🎯 Summary:
)> Except Arrow functions all normal function show the hoisting nature.
)> Var is hoisted , let & const are also hoisted only in the temporal deadzone.
Top comments (0)