Created
December 10, 2018 17:25
-
-
Save secilreel/92c20522e44dad33c30b3fe8355028d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Scope defines where Java Script can find a variable. If the variable is defined within a function, it has a block scope. | |
Otherwise, if the variable is outside of a function, it has a global scope. Global Scopes should be avoided because it might | |
change variables in other parts of the code, even outside of the original file. This is an undesirable side effect.Side | |
effects happen when a function reaches outside of its local scope and up into its parent; and, alters a value that is in there. | |
A side effect might create an indeterminate code, meaning a code that might not give the same result every time it runs. | |
To debug such a code would be both hard and frustrating. Instead, it is a good practice to have pure codes, which have no side | |
effects and are determinate, meaning they give the same result every time it runs. In order to avoid undesired side effects, | |
and not change variables in the global scope, it is a good practice to write 'strict mode' at the top of Java Script. Strict | |
mode will only allow changing variables within the file. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment