I am practicing some various JavaScript techniques, namely function properties. Here is something that has me scratching my head a little.
//property of the q0 function
q0.unique = 0;
function q0() {
return q0.unique++;
}
console.log(q0()); //returns 0
console.log(q0()); //returns 1
console.log(q0()); //returns 2
console.log(q0()); //returns 3
Shouldn’t the first call to the function return 1? Why is it returning 0? q0.unique is already set to 0?
That would be true if your code was:
The suffixed
++returns the current value then increments. With a prefixed++it’s the other way around.