Scope determines the level at which variables can be accessed and modified. Scope is determined by the scope chain, which is the standard for determining the scope of variables.
Local scope refers to the lowest level of the scope chain, and typically refers to block level (ie, inside levels of a function. Global scope refers to the highest level of the scope chain, and can be accessed across not only the current file, but all files across the app.
Global scope has the tendency to increase the likelihood of unintended side effects in code. Unintended side effects can make code error-prone and more difficult to debug.
Strict mode (which can be placed globally or scoped inside of functions) prevents the usage of variables that did not use let
or const
.
Side effects are when functions reach out of their scope into parent (or global) scope and change the values.
A pure function is one that is determinate (ie, always returns the same value when provided with the same inputs) and has no side effects.