Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Global counter
- var counter = 0;
- function add() {
- counter += 1;
- }
- // Local counter
- function add() {
- var counter = 0;
- counter += 1;
- }
- // Nested counter
- function add() {
- var counter = 0;
- function plus() {counter += 1;}
- plus();
- return counter;
- }
- // Closure counter
- var add = (function () {
- var counter = 0;
- return function () {return counter += 1;}
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement