Skip to content

Instantly share code, notes, and snippets.

@AitorAlejandro
Forked from henrik1/closure.js
Created June 3, 2022 12:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AitorAlejandro/e240ed092864de18a8c6071db77403d6 to your computer and use it in GitHub Desktop.
Save AitorAlejandro/e240ed092864de18a8c6071db77403d6 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