Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Question #1: What is scope? Your explanation should include the idea of global vs. block scope.
- Answer #1: Scope tells you where declared variables can be accessed in your code. Variables in global scope can be accessed anywhere
- throughout the code base and are created by defining a variable outside of a funtion or defining a variable without the use of "let"
- or "const". A variable in block scope is a variable that is defined within a funtion using "let" or "const". Block scope means that
- the variable lives inside of its home block and can not affect code outside of that block.
- Question #2: Why are global variables avoided?
- Answer #2: Global variables are generally to be avoided because due to their nature of being accessible anywhere throughout the code base,
- changing a global variable may have negative unintentional consequences elsewhere in your code. Global variables can even affect JavaScript
- code located in seperate files under certain conditions which may create bugs that are exceptionally hard to track and fix.
- Question #3: Explain JavaScript's strict mode.
- Answer #3: JavaScript's strict mode is a command that as a general recommended rule should be place at the top of every JavaScript file.
- Using strict mode makes it so that any time a variable is declared without using "let" or "const" an error will be triggered.
- Question #4: What are side effects, and what is a pure function?
- Answer #4: A side effect is when a function causes an unintentional change elsewhere in the code base. Side effects may be caused when
- using global variables.
- A funtion is considered to be a pure function when it possesses the following two qualities. A pure function must be determinate which
- means that it will always return the same outcome when given the same inputs. A pure function must also be free from side effects that
- cause issues with code located outside of the function.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement