CJCoding With Joseph
← Back to Question List
JavaScript Code Walkthrough #48

A Closure Keeps Private State

hardFunctions

📄 Code

Read carefully — what does this print?
1function makeCounter() {
2 let count = 0;
3 return function () {
4 count++;
5 return count;
6 };
7}
8let c = makeCounter();
9console.log(c());
10console.log(c());
11let d = makeCounter();
12console.log(d());
13console.log(c());

🎯 Your Answer