Timothy Tolley EDA

Starfish Raglan

JavaScript Scope

Scope refers to the range from which a specific variable can be accessed. There are two main types of scope - Global Scope and Local Scope. Scope is a question of the accessibility of a variable. Scope is essential

Global Scope

Global Scope is the all encompassing zone of the JavaScript file. Variables within this zone can be accessed from anywhere within the JavaScript file and can be accessed from within or outside of functions. Global scope is really important as it helps to make code shorter and enables access to things like API's throughout the file. It can be dangerous, however, with issues arising in terms of namespace clashes and bugs.

Local Scope

Local scope is beyond the global scope and functions and variables defined within a global scope cannot be accessed from within the global scope. A local scope can access all of its parent scopes' elements but cannot be accessed from those parents.