Created
January 20, 2018 19:39
-
-
Save schamblee/1244368268c1c3da4fe3f22ce8965f32 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. local scope. | |
Scope refers to the boundaries in which a variable or constant will interact with functions in code. | |
A variable has global scope when it is defined outside of a function. Global variables will be recognized | |
by functions throughout a folder of JS files. | |
A variable has local scope when it is defined within a function. A local variable is only recognized | |
within its function. | |
Why are global variables avoided? | |
As an app becomes more complex and requires many functions, global variables can cause there to be bugs | |
which are difficult to find. For example, if a global variable is defined in one JS file and altered in a function in another JS File in another, | |
it may be difficult to figure out why the variable has changed throughout the application. | |
Explain JavaScript's strict mode | |
JavaScript's strict mode is used to help a developer know when the code contains a variable which has not be | |
properly defined with the keywords 'let' and 'const'. when `strict most` is written at the top of a JS file, | |
it will result in an error if 'var' is used or if a variable is not defined within a function. | |
It is best practice to always use strict mode. | |
What are side effects, and what is a pure function? | |
Side effects are the result of global variables being altered by local functions in unattended ways. A pure function | |
is determinate, meaning that it reliably produces the same results if given the same inputs. Pure functions have no | |
side effects. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment