Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. Question #1: What is scope? Your explanation should include the idea of global vs. block scope.
  2.  
  3. Answer #1: Scope tells you where declared variables can be accessed in your code. Variables in global scope can be accessed anywhere
  4. throughout the code base and are created by defining a variable outside of a funtion or defining a variable without the use of "let"
  5. or "const". A variable in block scope is a variable that is defined within a funtion using "let" or "const". Block scope means that
  6. the variable lives inside of its home block and can not affect code outside of that block.
  7.  
  8. Question #2: Why are global variables avoided?
  9.  
  10. Answer #2: Global variables are generally to be avoided because due to their nature of being accessible anywhere throughout the code base,
  11. changing a global variable may have negative unintentional consequences elsewhere in your code. Global variables can even affect JavaScript
  12. code located in seperate files under certain conditions which may create bugs that are exceptionally hard to track and fix.
  13.  
  14. Question #3: Explain JavaScript's strict mode.
  15.  
  16. Answer #3: JavaScript's strict mode is a command that as a general recommended rule should be place at the top of every JavaScript file.
  17. Using strict mode makes it so that any time a variable is declared without using "let" or "const" an error will be triggered.
  18.  
  19. Question #4: What are side effects, and what is a pure function?
  20.  
  21. Answer #4: A side effect is when a function causes an unintentional change elsewhere in the code base. Side effects may be caused when
  22. using global variables.
  23.  
  24. A funtion is considered to be a pure function when it possesses the following two qualities. A pure function must be determinate which
  25. means that it will always return the same outcome when given the same inputs. A pure function must also be free from side effects that
  26. cause issues with code located outside of the function.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement