A Journey into the Abyss of Code

...follow the pink brick road...

❤ BLOGS HOME ❤ ❤ ABOUT ME ❤



Scope


What 'scope' is, and how it works in JavaScript.

There are two kinds of scope in JavaScript, global and local. Global scope refers to varaibles that are defined outside of a function and can be accessed and modified from anywhere. Whereas local variables are defined withtin a function and can only be accessed within the function.

Think of it like a locked house. The variable inside the locked house (function) has a local scope and cannot be accesed from outside, however a variable outside the house (function) can be accessed from anywhere because it is not bound by the same restrictions as the variable with a local scope.