Guest User

Untitled

a guest
Jan 19th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. What is scope? Your explanation should include the idea of global vs. local scope.
  2. Why are global variables avoided?
  3.  
  4. -scope has to do with how far within a program any one variable can be affected or be of affect. That being said, any global variable(any variable set outside of any particular function) will overwrite any variable that's undefined within any function of an entire program. This can get very tricky even when considering a small program with just 100 lines of code but staggering when looking at a program with 1000+ lines of code. For an example, lets consider an app that calculates the batting average for multiple baseball players. In the code (for arguements sake) each player is going to be a seperate function. Now (for arguements sake) each players 'average' is going to be a seperate local variable within each function(player) to work properly and get the average for just that player(function). After coding 100's of players lets assume you forget to declare a few 'average' variables for some of the players(functions). On top of that you think it would be a nifty idea to delare a global 'average' variable to calulate the batting average for the entire league. One doesn't need a PhD in mathematics to understand that for an algorithym to work properly it can not have multiple places to reference data for any one particular instance.
  5.  
  6. Explain JavaScript's strict mode
  7.  
  8. -as a header i would like to note that non strict mode is also refered to as 'sloppy mode'. that being said, in my own words, i can not explain how each browser handles or interprets 'strict mode' but in general it throws any variable NOT declared as 'let' or 'const' into error.
  9.  
  10. What are side effects, and what is a pure function?
  11.  
  12. -in my own words side effects are when variables effect application state outside of its 'called' function. a pure function is when variables stay within their isolated functions and dont cause side effects. my above analogy is a perfect example of when applications have impure functions that cause side effects.
Add Comment
Please, Sign In to add comment