Scope

Sean Ransonette
2 min readOct 23, 2021

Topic for this week will be scope. When I originally started coding, scope took me a little bit to grasp. Scope is defined as the current context of code, which then determine the accessibility of variable. There are 2 main types of scope. Local scope and Global scope. Within Local Scope there can also be block or function scope.

Global Scope is where everything in a JavaScript program executes by default. This scope is able to include all variable, objects, and references that are not contained within a otherwise local scope defined by the programmer. Global Scope is an entire JavaScript environment.

Local Scope is when you are working inside of a function. When you create a variable inside of a function, that variable has local scope. If you where to call on the variable outside of a function that was declared inside of one, you would find that you cannot access the variable in the function from the outside. Block scope inside of a local scope just means declaring a variable inside of a function but also in curly brackets, like if statements or loops

These are the various forms of scope. It is extremely important to understand scope to effectively declare variables so that all of your functions work properly.

--

--