Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // What is scope? Your explanation should include the idea of global vs. local scope //
- Scope is the measure of 'reach' or 'area' in which you can access a variable.
- A variable with a global scope, or global variable, is a variable that is declared outside of a function and can
- be accessed anywhere, in most cases it can be accessed in external files as well.
- A variable with a local scope, or local variable, is a variable that can only be accessed within the function in
- which it was declared.
- // Why are global variables avoided? //
- Global variables are to be avoided because of the likelihood of unintended side effects, resulting in lots of bugs,
- often hard to track. Global variables can also cause many functions to have indeterminate results (inconsistent
- results due to the values of variables changing).
- // Explain Javascript's strict mode //
- 'strict mode';, when put at the very top of your code will make it so JS will throw an error when you attempt to
- declare a variable without using 'let' and 'const'. This is the fix for global variable related bugs.
- // What are side effects, and what is a pure function? //
- A side effect is when a function reaches outside of its local scope and changes a value in the parent scope.
- A pure function is a function in which its result, given the same inputs, will always be the same and with no side effects.
Add Comment
Please, Sign In to add comment