Created
July 30, 2019 00:17
-
-
Save martellinick/b77f01040fa12bc58cb91709fb83b924 to your computer and use it in GitHub Desktop.
Variable Scope Questions
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. block scope. | |
Scope is how the variables within your code can or can't be accessed at different points within your code. Global scope is | |
when a variable can be accessed from anywhere within your code. This means that any code not declared within block code can | |
be accessed globally. Block scope is when variables can only be accessed within a function and outside of that function | |
they don't exist. | |
Why are global variables avoided? | |
Global variables are avoided because they can have unintended consequences on other areas of the code. If a global variable | |
were to be used in a function without the use of "let" or "const", that global would be accessed and altered which would | |
then change any other functions that access that global variable. | |
Explain JavaScript's strict mode | |
Strict Mode is something that the programmer can write into the beginning of the code that allows Javascript to throw an | |
error code whenever a variable is declared without the use of let" or "const". | |
What are side effects, and what is a pure function? | |
Side effects are when a function goes outside its local scope up into a parent scope and alters a value that lives there. | |
A pure function is when a function will always return the same value if it's provided with the same inputs without any | |
side effects. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment