Hoisting Trap in JS⚠️ | What’s the Log? 92
Автор: Web & Beyond
Загружено: 2025-11-09
Просмотров: 84
Описание:
Inside the function, var x is hoisted, meaning it is moved to the top of its scope but without its value.
So the function fun() is interpreted like:
function fun() {
var x; // hoisted (initially undefined)
console.log(x); // → undefined
x = 5;
console.log(x); // → 5
}
The outer x = 10 is not used inside the function because the local var x shadows it.
So final output is:
undefined
5
10
Key Takeaways
✅ var is hoisted with value undefined
✅ Local variable shadows global variable
✅ Always know where your variable actually lives in scope
✨ Support the channel
☕ Buy me a coffee → https://buymeacoffee.com/webnbeyond
🇮🇳 For Indian viewers → UPI: wnb26@ptyes
(Helps me create more free content 🙌)
🌐 Need hosting? 💰 Use this link to get 20% EXTRA discount 🎉
Get fast & affordable hosting → https://shorturl.at/7Ej1K
📦 Developer Essentials:
👓 Protect your eyes → https://amzn.to/4mHta4I
💻 Keep your laptop cool → https://amzn.to/45obqpm
📝 Quick reminder tool → https://amzn.to/3UzgukA
📚 Full list of books & gear I recommend → https://rebrand.ly/9yiqge6
⚠️ Disclaimer: These links are affiliate links—I may earn a small commission at no extra cost to you.
#javascript #whatsTheLog #codingshorts #codingchallenge #learnjavascript #webdevelopment #javascripttips #javascriptinterview #javascriptinterviewquestions #happycoding
Повторяем попытку...
Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: