Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. What is scope? Your explanation should include the idea of global vs. block scope.
  2. Variable scope is a set of rules that define which part of the code can alter a pariticular variable.
  3. It allows us to reuse variable names at different points in our code without enoutering bugs or glitches.
  4. There are two types of scope called global and block scope. Global scopes are any variables declared outside of a function.
  5. On the otherhand, block scopes are variable decalred within a fucntion and is only accessible within that function's block of instructions.
  6.  
  7.  
  8. Why are global variables avoided?
  9. Global variables should be avoided because of uninteded side effects they may cause.
  10. Global scopes may span across files, and therefore may cause uninteded consequences or changes if two separate files share the same variable.
  11. Functions may also unintentially affect and change the values of global variables.
  12.  
  13.  
  14.  
  15. Explain JavaScript's strict mode
  16. JavaScipt's strict mode prevents global scope and therefore potential bugs within our codes.
  17. You can put 'use strict' on top of the the JavaScript file or on top of a function.
  18. When this is used, anytime a variable is delcared without the 'let' or 'const' keywords, an error will trigger.
  19. The trigger will say 'Uncaught ReferenceError' when it is triggered.
  20.  
  21.  
  22. What are side effects, and what is a pure function?
  23. A side effect is when a function reaches outside its local scope and it starts to look up into a parent scope and then alters a value that lives there.
  24. Uninteded side effects and global variables together can result in the codes becoming an indeterminate function.
  25. These functions (the indeterminate funciton) return one value some times and another value another time.
  26. Pure function, on the other hand, is determinate and has no side effects.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement