JavaScript Hoisting and Temporal Dead Zone Explained

🚀 JavaScript Interview Question You Should Know ❓ What will be the output? console.log(a); var a = 10; console.log(b); let b = 20; 💡 Output: undefined ReferenceError: Cannot access 'b' before initialization 🧠 Explanation: 👉 var a Variables declared with var are hoisted They are initialized with undefined So internally: var a; console.log(a); // undefined a = 10; 👉 let b let is also hoisted BUT… It stays in the Temporal Dead Zone (TDZ) until initialized So accessing it before initialization: console.log(b); // ❌ ReferenceError let b = 20; 🎯 Key Takeaways: ✔ var → hoisted + initialized as undefined ✔ let/const → hoisted but NOT initialized (TDZ) #JavaScript #WebDevelopment #Frontend #CodingInterview #LearnToCode

  • graphical user interface, application

To view or add a comment, sign in

Explore content categories