Created
September 25, 2019 01:58
-
-
Save lwebber/bc7fc26ae9006efdf0b91a812dedfaf3 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
What is scope? Your explanation should include the idea of global vs. block scope. | |
Scope refers to the area in which a variable is active or accessible. Block scope refers to variables that a defined within | |
a block and thus only accessible within the block. Global variables are defined outside a block and are accessible throughout | |
a file and even between files, provided the global variable is defined in a file that is read before another file that | |
uses that variable. | |
Why are global variables avoided? | |
The problem with global variables is that they can be changed by one function and that variable might then be used in | |
another function and doesn't expect that the value of the variable might have changed. Bugs and unexpected side effects | |
could occur. | |
Explain JavaScript's strict mode | |
Strict mode forces you to use const or let when defining variables, thus avoiding the unintended creation of global | |
variables. | |
What are side effects, and what is a pure function? | |
Side effects are unintended consequences, like if you change the value of a variable but that variable is used some- | |
place else and the value change alters the output of that second function. A pure function is one that has no unintended | |
side effects and is also determinate, meaning it always generates the same output given the same input. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment