Guest User

Untitled

a guest
Jan 24th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. What is scope? Your explanation should include the idea of global vs. local scope.
  2. Scope is the scale of what a particular variable can interact with. For instance if a variable is delcared outside of a function the scope would be global. Any future functions that call that particular variable outside the function. Local scope is a variable declared only in inside the function.
  3. Why are global variables avoided?
  4. Global variables can cause indeterminate functions, which mean that given the same inputs a function can produce multiple outputs.
  5. Explain JavaScript's strict mode
  6. Strict mode assumes all variables decleared without let or const is an error.
  7. What are side effects, and what is a pure function?
  8. Side effects are the unintented mutations of varibles. If a global variable is decleared and a function mutates the variable it could cause pure functions to become indeterminate.
  9. Example below;
  10.  
  11. // tip calculator
  12. const prices = 10;
  13. const customers = 3;
  14. // to make this simple set price and customers
  15. let tip = 0.2;
  16. // 20% tip as a baseline
  17. let tax = 0.0175;
  18.  
  19. let bill = prices * customers + tax;
  20.  
  21. function getTip() {
  22. bill += tip * bill;
  23. return bill;
  24. }
  25. function receiptPrint() {
  26. console.log(' Your Bill is = $'+ bill + ' Tip _____' + ' Total ______');
  27. }
  28.  
  29. getTip();
  30.  
  31. receiptPrint();
  32.  
  33.  
  34. /* the receipt would print the base bill with the tip included since the getTip function variable is global in scope. */
Add Comment
Please, Sign In to add comment