Created
May 24, 2022 09:33
-
-
Save henrik1/e80605683fa0d720ff9c9b6e32da5dff 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