Skip to content

Instantly share code, notes, and snippets.

@jaySmilet
Created February 17, 2025 12:13
Show Gist options
  • Select an option

  • Save jaySmilet/4f771207089abf6c46a41b593b412689 to your computer and use it in GitHub Desktop.

Select an option

Save jaySmilet/4f771207089abf6c46a41b593b412689 to your computer and use it in GitHub Desktop.
Closures
function createCounter() {
let count = 0;
return function() {
count += 1;
return count;
};
}
let counter = createCounter();
console.log(counter()); // 1
console.log(counter()); // 2
console.log(counter()); // 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment