Home / Javascript Tips Generated By ChatGPT / Simple Counter with Closure in Javascript Use closure to create a private counter. Source Code function makeCounter() { let count = 0; return function() { return ++count; }; } let counter = makeCounter(); console.log(counter()); // 1 console.log(counter()); // 2