Vivek Dubey’s Post

🚨 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗖𝗵𝗲𝗮𝘁𝘀𝗵𝗲𝗲𝘁 𝗩𝗮𝗿 𝘃𝘀 𝗟𝗲𝘁 𝘃𝘀 𝗖𝗼𝗻𝘀𝘁 — 𝗨𝗻𝗱𝗲𝗿𝘀𝘁𝗮𝗻𝗱 𝗶𝗻 𝗢𝗻𝗲 𝗥𝗲𝗮𝗱 👇 Most developers say: ❌ “Hoisting doesn’t work with let and const” But that’s NOT true. 👉 Hoisting happens with var, let, and const. The real difference is how they behave after hoisting. Let’s break it down clearly 👇 🟧 𝗩𝗔𝗥 — Old & Risky • Scope: Function scoped • Hoisting: Yes → initialized with undefined • Re-declaration: ✅ Allowed • Re-assignment: ✅ Allowed • Initialization: Optional ⚠️ Can be accessed before declaration → bug-prone 🟦 𝗟𝗘𝗧 — Modern & Flexible • Scope: Block scoped • Hoisting: Yes → Temporal Dead Zone (TDZ) • Re-declaration: ❌ Not allowed • Re-assignment: ✅ Allowed • Initialization: ✅ Required ❌ Access before initialization → ReferenceError 🟩 𝗖𝗢𝗡𝗦𝗧 — Constant & Fixed • Scope: Block scoped • Hoisting: Yes → Temporal Dead Zone (TDZ) • Re-declaration: ❌ Not allowed • Re-assignment: ❌ Not allowed • Initialization: ✅ Required 🔒 Best choice for fixed values 🚫 𝗔𝘃𝗼𝗶𝗱 𝘃𝗮𝗿 ✅ 𝗨𝘀𝗲 𝗹𝗲𝘁 for changeable values 🔐 𝗨𝘀𝗲 𝗰𝗼𝗻𝘀𝘁 for fixed values 📌 𝗢𝗻𝗲-𝗹𝗶𝗻𝗲 𝗺𝗲𝗺𝗼𝗿𝘆 𝘁𝗿𝗶𝗰𝗸: 👉 var = function scoped + undefined 👉 let = block scoped + TDZ 👉 const = block scoped + no re-assign If this clicks once, your JavaScript scoping confusion disappears 💡 📌 Save this for interview revision 💬 Comment if hoisting or TDZ confused you earlier 👍 Follow for clear JavaScript & React breakdowns #JavaScript #ReactJS #FrontendDevelopment #WebDevelopment #TechInterviews #LearningInPublic

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories