Skip to content

Instantly share code, notes, and snippets.

@elliotkim916
Created September 16, 2017 02:09
Show Gist options
  • Save elliotkim916/2bd7a620e577df05e4e352ca32fe715f to your computer and use it in GitHub Desktop.
Save elliotkim916/2bd7a620e577df05e4e352ca32fe715f to your computer and use it in GitHub Desktop.
In Your Own Words...
Variable scope can be defined as how the variables you declare either can or cannot be accessed at different points in your code.
With global scope, any variable that is declared outside of a Javascript function has global scope.
Inside Javascript functions are local scopes and with the scope chain, Javascript follows the scope chain to determine the value of the variable.
Global variables are avoided because they tend to make unintended side effects more likely.
Also, global variable along with unintended side effects almost guarantee that the code becomes indeterminate, meaning
given a single set of inputs, returns one value sometimes and another at other times.
Whenever Javascript's strict mode is enabled, anytime a variable is declared without const or let, an error will be triggered.
A Side Effect is when a function reaches outside its local scope, up into a parent scope, and alters a value that lives there.
A Pure Function is when a function is both determinate and has NO side effects.
Determinate means one that will always return the same value, if its provided with the same inputs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment