Guest User

Untitled

a guest
May 22nd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. What is scope? Your explanation should include the idea of global vs. local scope.
  2. Scope is the concept of where values are stored and what parts of your code can access them.
  3. If a value is stored in the global scope, this means that they can be accessed and
  4. manipulated anywhere in your code and even in other files. Values stored in local or
  5. block scope only exist inside of the function they are placed in. They can be manipulated
  6. within that function, but do not affect the scope(s) outside of them. A locally declared
  7. variable can have the same name as a parent-scope variable, but it will not affect the outside
  8. variable.
  9.  
  10. Why are global variables avoided?
  11. Using global variables tends to cause code to get buggy. The function reaches outside of its local
  12. scope and starts to change the world around it. This is undesired because it causes functions to be
  13. indeterminate. This means a function can run with the same input many times and get a different
  14. result each time. This is to be avoided unless you're meant to update the parent value.
  15.  
  16. Explain JavaScript's strict mode
  17. By putting 'use strict'; at the top of your JavaScript file, you force it to error whenever you
  18. try to declare a value without using the declaration keywords 'let' or 'const.' You can also
  19. use strict mode locally by placing it on top of your function block rather than at the top
  20. of your JavaScript file. Unless you have a reason not to, you should always use local scope, and
  21. 'use strict'; at the top of your file.
  22.  
  23. What are side effects, and what is a pure function?
  24. Side effects are what happens when a function reaches outside of its local scope and changes values
  25. stored in a parent scope. A pure function is one which does not do this, and also returns the same value
  26. every time it is fed the same input. Determinite and side-effect free!
Add Comment
Please, Sign In to add comment