Whenever you access a variable JavaScript uses something called the scope chain to determine which variable you are referring to.

The scope chain works like this, JavaScript starts looking for the variable in the scope in which it is called, if it can’t find it within that scope it moves up to the next level and looks there, it keeps doing this until it hits the global space, and if it can’t find it in the global scope it throws an error.

I think that the ODB captured this perfectly when he said “You see my name is something that you won’t know unless you’re down with the Brooklyn Zoo”. …

About

Joseph Haefling

I am a front-end software engineer, a former social worker, an amateur musician, a foodie, and a recent graduate of Turing School of Software and Design.

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