Created
October 31, 2018 14:53
-
-
Save thebinarypenguin/75681c4d08861a1a472d96b25868e7a4 to your computer and use it in GitHub Desktop.
JavaScript Scope Challenge
This file contains hidden or 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. local scope. | |
Scope is the area in which a variable is accessible. Variables declared at | |
the top level of an application have global scope and are accessible by all | |
code. While variables declared inside a function have local scope and are only | |
accessible by the code in that function. | |
Why are global variables avoided? | |
A global variable is essentially a variable that is shared among all the code | |
in the application. Which means function A can change the value of the | |
variable without function B knowing about it. Then when function B goes to use | |
the variable it will be in the wrong state and errors will occur. It's a bit | |
like when your roommate drinks all the milk and you are stuck eating dry | |
cereal. | |
Explain JavaScript's strict mode | |
Strict mode instructs the JavaScript interpreter to be more harsh when | |
evaluating code. Some types of code which are technically valid but are | |
considered bad practice or likely to be the source of subtle errors are | |
considered errors by strict mode. Strict mode is your friend. | |
What are side effects, and what is a pure function? | |
A pure function is a function that does not have any side effects. Side | |
effects are changes to state outside of the function's own local scope. A pure | |
function takes it's input via its arguments, does all its work in its own | |
local scope, and then provides its output via the return keyword. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment