Skip to content

Instantly share code, notes, and snippets.

@henrik1
Created May 24, 2022 09:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save henrik1/e80605683fa0d720ff9c9b6e32da5dff to your computer and use it in GitHub Desktop.
Save henrik1/e80605683fa0d720ff9c9b6e32da5dff to your computer and use it in GitHub Desktop.
Closure example
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