Guest User

Untitled

a guest
Jul 20th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. What is scope? Your explanation should include the idea of global vs. local scope.
  2. Scope in the extent of JavaScript determines what specific parts of the program are accessible.
  3. Variable scope is the idea that certain variables can or cannot be accessed depending on where and how they’re declared.
  4.  
  5.  
  6. Why are global variables avoided?
  7. In javascript variable declared inside a function has local scope(accessible only within the block of that function.)
  8. If a variable inside a function has the same name as a global variable(outside a function), the local variable takes precedence
  9. and is then altered to the new declared value. In other words, a function can change the value of a global variable.
  10. If another function comes along that depends on the original value of the global variable, this can create problems
  11. and break the program.
  12.  
  13. Explain JavaScript's strict mode
  14. As I understand it, a variable without var, let or const is automatically a global variable.
  15. To avoid this, JavaScript has a strict mode feature so that any variable declared without let or const creates an error.
  16. It’s like variable proofing.
  17.  
  18. What are side effects, and what is a pure function?
  19. A side effect is when a function goes outside of its local scope and starts changing values in parent scopes.
  20. If other parts of the program are depending on the original values and the function comes along and changes them,
  21. this creates indeterminate code. Meaning, if I give the function the same input, sometimes it gives me one thing and
  22. other times it gives me another thing. It is not reliable 100% of the time. A pure function is determinate code.
  23. That is, if I give that function the same input it will return the same thing 100% of the time.
Add Comment
Please, Sign In to add comment