Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. 1. What is scope? Your explanation should include the idea of global vs. block scope.
  2.  
  3. Scope refers to the function or block level in which a particular a variable is defined. The global scope refers to variables defined at the top level of the program, I.E. not inside of any function or code block. Block scope refers to variable definitions contained in curly brackets { }, which are not accessible from outer/upper scopes and are deleted from memory upon completion of the code block or function.
  4.  
  5. 2. Why are global variables avoided?
  6.  
  7. Use of global variables can excessively increase the complexity, unpredictability, and memory footprint of code. Functions whose output is purely determined by the input are easier to test and debug compared to functions whose behavior depends on unpredictable global variable state.
  8.  
  9. 3. Explain JavaScript's strict mode
  10.  
  11. This mode throws an error if a variable is assigned a value before a proper definition via the var, let, or const keywords. It can prevent a situation in which a new variable was intended, but instead a higher scope variable is used, in the case they share names.
  12.  
  13. 4. What are side effects, and what is a pure function?
  14.  
  15. Side effects are when a function alters the global state. A pure function is one that does not use global variables in its code nor explicitly alters the global state. Thus a pure function's return value only depends on the input values.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement