CJCoding With Joseph
15free / daySign inCreate account
Back to Code Walkthrough

A Closure Keeps Private State

JavaScript code walkthrough · Question 48
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