Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. What is scope? Your explanation should include the idea of global vs. block scope.
  2. A scope is basically defining which part of your code can access certain variables. There are two different kinds of scope:
  3. global and block scope. Block scope is where the variable is only accessible in your function. Global scope is where the
  4. variable is accessible everywhere, including other files. Global scope tends to cause unintended side effects, which almost
  5. guarantee your code to become indeterminate.
  6.  
  7. Why are global variables avoided?
  8. Because they tend to cause unintended side effects, leading your code to almost guarantee to become indeterminate, which is
  9. something we do not want. We want our code to be pure. In other words, we want our code to not have unintended side effects
  10. and be determinate.
  11.  
  12. Explain JavaScript's strict mode
  13. JavaScript's strict mode allow us to avoid pitfalls like the unintended side effects. When strict mode is enabled, everytime
  14. when the keyword "let" or "const" is not used to declare a variable an error will occur. Strict mode can be enabled by adding
  15. 'use strict' at the top of the JavaScript file or function if you only want to use it for the body of the function. However,
  16. the general rule is to place it at the top of the file.
  17.  
  18. What are side effects, and what is a pure function?
  19. Side effect is when a variable goes outside of its local scope, up into its parent scope, and alter the value there.
  20. Unintended side effects tends to be caused by global scope.
  21. A pure function is a function that has no side effects and is determinate - it will always return the same value given that
  22. it is always provided with the same input.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement