-
-
Save AitorAlejandro/e240ed092864de18a8c6071db77403d6 to your computer and use it in GitHub Desktop.
Closure example
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
function counter() { | |
let count = 0; | |
function increment() { | |
return count += 1; | |
}; | |
return increment; | |
} | |
const generateId = counter(); | |
generateId(); // 1 | |
generateId(); // 2 | |
generateId(); // 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment