Guest User

Untitled

a guest
Apr 26th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. // What is scope? Your explanation should include the idea of global vs. local scope //
  2. Scope is the measure of 'reach' or 'area' in which you can access a variable.
  3. A variable with a global scope, or global variable, is a variable that is declared outside of a function and can
  4. be accessed anywhere, in most cases it can be accessed in external files as well.
  5. A variable with a local scope, or local variable, is a variable that can only be accessed within the function in
  6. which it was declared.
  7.  
  8. // Why are global variables avoided? //
  9. Global variables are to be avoided because of the likelihood of unintended side effects, resulting in lots of bugs,
  10. often hard to track. Global variables can also cause many functions to have indeterminate results (inconsistent
  11. results due to the values of variables changing).
  12.  
  13. // Explain Javascript's strict mode //
  14. 'strict mode';, when put at the very top of your code will make it so JS will throw an error when you attempt to
  15. declare a variable without using 'let' and 'const'. This is the fix for global variable related bugs.
  16.  
  17. // What are side effects, and what is a pure function? //
  18. A side effect is when a function reaches outside of its local scope and changes a value in the parent scope.
  19. 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