Stop misleading people with the 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

--

--

--

Software engineer.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Create Material UI TextField variants

material ui textfield variants

React Movie Application

Mapping a String

Multiple API Calls in React using AXIOS with Loading and Error Handling 🔥

Multiple API Calls in React using AXIOS with Loading and Error Handling 🔥

The 4 Most Telltale Signs of a Lonely Programmer

What is buffer in Node.js ?

My Weekly React Learning Series

Introduction To Polyfills & Their Usage

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ekebor Kelechi

Ekebor Kelechi

Software engineer.

More from Medium

Technical Analysis -Training Plan

Abridged tales of the Mario Kart DS hacking scene, from MKDSOSE to CTGP Nitro

You’ve got 10 seconds…

Machine Learning as a method of Bitcoin price forecasting