JavaScript Interview Question: Local Variable Shadowing

🚀 JavaScript Interview Question That Many Developers Get Wrong! I recently came across an interesting JavaScript interview question: 💡 What will be the output? ➡️ 10 🔍 Why? Because JavaScript has: Function scope Local variable shadowing Closures Even though x = 15 creates a global variable, the inner() function has its own: let x = 10; This local variable shadows the global one. So the global x never affects the value returned by inner(). Understanding these small details is what separates a good JS developer from a great one! 💪 🧠 Key Takeaways ✔ JavaScript is single-threaded but supports async behavior ✔ Local variables always override global variables ✔ Closures retain access to their lexical scope ✔ Missing let/const creates global variables (bad practice!) #javascript #webdevelopment #interview #coding #frontend #reactjs #mern #nextjs #learnjavascript #softwareengineering

  • text

To view or add a comment, sign in

Explore content categories