Guest User

Untitled

a guest
Apr 25th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. I like to think about scope like a cheeseburger. Double with cheese, bacon, lettuce, tomatoes, pickles, and mustard.
  2. So global scope would be like when you take a bite somewhere in the middle. It doesn’t really matter where you bite, because
  3. you’ll always have access to all the toppings. Local would be like you pulled a tomatoe out and just took a bite of tomatoe.
  4. That bite only affects the tomatoe. If I just bite into the tomatoe, the rest of the cheeseburger is relatively unaffected. So running
  5. something with local scope has fewer effects on the application as a whole.
  6.  
  7. Before talking about strict mode, we have to realize that not everyone likes the same cheeseburger. Some might want
  8. onions instead of pickles. Or maybe there was a miscommunication and you got a veggie burger instead of 80/20 chuck.
  9. In order to explicitly put in our order to prevent mistakes and get the desired result (not everyone likes a global cheeseburger),
  10. we need a way to say, “Hey, JS, this is what we want.” That‘s where use strict comes in. In strict mode, variables have to be declared
  11. before they can be used.
  12.  
  13. Use strict is useful because it keeps accidents like that from happening. Variables are much less likely to get accidentally
  14. reassigned. Kind of like how at BK you can get it your way, with use strict, if something isn’t explicitly declared, then there
  15. will be an error. “Excuse me, I did not order bacon. I ordered Canadian bacon.”
  16.  
  17. So use strict helps with preventing side effects where variables accidentally get changed or reassigned. It forces you to
  18. think about the variables you are using, and maybe using const instead of let, and vice versa.
  19.  
  20. Pure functions are functions that simpy return the same output everytime when given the same input. For an array in Javascript, it's
  21. like using slice (pure function) vs splice (side effect of changing the original array everytime it's called).
Add Comment
Please, Sign In to add comment