Open this example in the interactive library
Source code
function counter() {
let value = 0;
return () => ++value;
}
const a = counter(),
b = counter();
console.log(a(), a(), b());
Sample output
1 2 1

Open this example in the interactive library
function counter() {
let value = 0;
return () => ++value;
}
const a = counter(),
b = counter();
console.log(a(), a(), b());
1 2 1