Created
June 4, 2018 20:57
-
-
Save neerajkumar/78fd2552e56266f8ba10ca5254963f67 to your computer and use it in GitHub Desktop.
Javascript Closure Counter Solution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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