Advertisement
Guest User

Untitled

a guest
Feb 21st, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. // Global counter
  2. var counter = 0;
  3.  
  4. function add() {
  5. counter += 1;
  6. }
  7.  
  8. // Local counter
  9. function add() {
  10. var counter = 0;
  11. counter += 1;
  12. }
  13.  
  14. // Nested counter
  15. function add() {
  16. var counter = 0;
  17. function plus() {counter += 1;}
  18. plus();
  19. return counter;
  20. }
  21.  
  22. // Closure counter
  23. var add = (function () {
  24. var counter = 0;
  25. return function () {return counter += 1;}
  26. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement