Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. 1. What is scope? Your explanation should include the idea of global vs. block scope.
  2.  
  3. scope is the environment in which items like objects and functions are available. block scope, for example,
  4. is the environment within a block, such as a for loop, a function, or an object. in block scope, variables are
  5. considered 'local'. global scope is the environment that contains everything that wasn't declared inside of
  6. a block. in vanilla js, this is typically the window object.
  7.  
  8. 2. Why are global variables avoided?
  9.  
  10. global variables are avoided mainly because they can cause collisions, such as name conflicts with external resources,
  11. other scripts, window properties, etc. they're also avoided because they're technically slower to reference than local
  12. variables.
  13.  
  14. 3. Explain JavaScript's strict mode
  15.  
  16. in strict mode, many things are changed to prevent certain behaviors. for example, if a variable is declared without
  17. any variable keyword (like let, const, or var) in non-strict mode, that variable becomes a property in global namespace.
  18. however, in strict mode, doing this just throws an error. also, assigning values to non-writable items like NaN (which just
  19. fails silently in non-strict) throws an error. strict mode has many, many other features as well, mainly meant to prohibit
  20. illegal / discourages practices in javascript.
  21.  
  22. 4. What are side effects, and what is a pure function?
  23.  
  24. side effects are unintended behaviors of a script, usually as a result of mistakes that were made in writing: such as a function
  25. modifying objects outside of its scope that it isn't meant to access.
  26.  
  27. a pure function has no side effects, and also always provides x output for y input every time it is called. an example of
  28. a typical pure function would be a hashing algorithm.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement