Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. What is scope? Your explanation should include the idea of global vs. block scope.
  2. Scope is the space in the code in which a defined variable is able to be used. When the JavaScript interpreter comes across a variable, it first looks locally, then moves up the chain to the parent, and then the next parent, until it gets to the global level, to see where that variable has been defined.
  3. It is generally more ideal to use block scope, meaning that your variable is defined within that block of code or function only, so that variables have the most minimal likelihood of being affected by code outside of that block. If global scope is used, on the other hand, it means that your variable is defined throughout all of your code within a program, meaning that your variable could cause problems if it is changed within a certain block of code.
  4.  
  5. Why are global variables avoided?
  6. If your variable is defined globally, it could be changed in a function, and this change could affect a later function in which the same variable is called again, which could cause side effects, or bugs, or generally, could cause your program to behave in a way that is undesirable.
  7.  
  8. Explain JavaScript’s strict mode.
  9. The main advantage of strict mode that we are concerned with here is that it forces code to be written with variables that are strictly defined with let or const, so that they are unlikely to be changed (because changing variables can cause bugs).
  10. In general though, strict mode is a very useful tool to use when writing code, because it can help prevent errors/mistakes, or make errors within your code more obvious.
  11.  
  12. What are side effects, and what is a pure function?
  13. Side effects are what happens when some code alters other code that is outside of the local scope (for example, in the parent scope or global scope).
  14. A pure function is a function that does not have any side effects, and also always returns the same value given the same inputs--therefore it hasn’t been changed at any point by other code.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement