Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. function logScope() {
  2. // this could also be var localVar = 2
  3. let localVar = 2;
  4.  
  5. if (localVar) {
  6. let localVar = "I'm different";
  7. console.log("nested localVar: ", localVar);
  8. }
  9.  
  10. // localVar that is in the logScope function
  11. console.log("logscope localVar: ", localVar);
  12. }
  13.  
  14. // run the function
  15. logScope();
  16.  
  17.  
  18. // another example using let
  19. function lotsOfApples() {
  20. let localApples = "green apples";
  21.  
  22. if (localApples) {
  23. let localApples = "rotten apples";
  24. console.log("nested let variable:", localApples);
  25. }
  26.  
  27. console.log("entire scope let variable: ", localApples);
  28. }
  29.  
  30. lotsOfApples();
  31.  
  32.  
  33. // an example of using a const
  34. const MYHOMEWORK = "Programming with Javascript";
  35. console.log(MYHOMEWORK);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement