I was going through a JS tutorial, and came across this example:
function makeCounter() {
function counter() {
return counter.count++;
};
counter.count = 0;
return counter;
}
let counter = makeCounter();
counter.count = 10;
console.log(counter()) // logs 10
What I don't understand is why it didn't log 11 instead of 10? If we have set the count
property to 10
and stored the function counter
that increments count
property, why the property is not incremented then to 11?