Skip to content

Instantly share code, notes, and snippets.

@neerajkumar
Created June 4, 2018 20:57
Show Gist options
  • Save neerajkumar/78fd2552e56266f8ba10ca5254963f67 to your computer and use it in GitHub Desktop.
Save neerajkumar/78fd2552e56266f8ba10ca5254963f67 to your computer and use it in GitHub Desktop.
Javascript Closure Counter Solution
var add = (function () {
let counter = 0;
return function() {
return counter += 1;
};
})();
console.log(add());
console.log(add());
console.log(add());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment