Ekebor Kelechi
1 min readJan 22, 2022

Stop misleading people with the var variable is function scoped.

I’ve read a lot of articles on medium on var scope. So many of them will say var variables are function scoped but they fail to explain what happens when you use a var on a block scope and how it happens under the hood.

Lol this article is courtesy of the frustration i got trying to really understand scoping in javascript for the 100th time, especially after i thought i had understood that thing.

So like the rest of the articles say, var variables are function scoped but if you ever use a var variable in a block scope, you wont exactly get a reference error like I though it would.

What happens under the hood is that javascript engines reads it as a global variables there by making it a global scope.

I’m not quite sure how it does this but hey, just incase you ever wondered.

To be continued

Ekebor Kelechi
Ekebor Kelechi

No responses yet