Created
February 17, 2025 12:13
-
-
Save jaySmilet/4f771207089abf6c46a41b593b412689 to your computer and use it in GitHub Desktop.
Closures
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 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