Guest User

Untitled

a guest
Nov 21st, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. 1.
  2. Scope, I guess you could say is like the area of effect that a variable is available for reference. Variables declared in the
  3. global scope are available for reference and manipulation when variables within functions are not properly declared in their local scope. Any variable declared outside of a function is a global variable.
  4. Variables declared in the local scope, should always be declared using let or const as to avoid side effects. Variables properly
  5. declared in the local scope will be referenced locally and will not bubble up to parent variables and consequentially and potentially
  6. the global scope. Any variable declared inside a function is a local variable.
  7.  
  8. 2.
  9. Global variables are avoided because they give way to a number of problems in your code including: unintended side effects, and
  10. indeterminate functions. Side effects can be that a function reaches out of its local scope and changes the value of a global variable
  11. that in turn will change the output of other functions that reference that global variable creating indeterminate values.
  12.  
  13. 3.
  14. JavaScript has a mode called 'strict mode'. It is considered best practice to always use this mode, unless you have a specific
  15. reason not to do so. The purpose of 'strict mode' is to prevent to accidental manipulation of global scope variables in functions
  16. that reach out of local scope by always requiring the declaration of variables using 'let' or 'const'
  17.  
  18. 4.
  19. As noted before, side effects happen when a function reaches out of its local scope and alters the value of a global variable.
  20. This occurs when a variable with the same name is not redeclared within the local scope of the function.
  21. A pure function is a function that is both determinate and has no side effects, meaning it will always return the same value provided that the input is the same everytime and that it does not reach beyond its local scope and alters the value of a global variable.
Add Comment
Please, Sign In to add comment