Basically, the way the postfix ++ (specificially ++ AFTER a variable) is like a special function. It performs 2 actions
- Adds one to the variable
- Returns the variables original value
Compare this to a prefix operator, ++num1, which performs these 2 actions:
- Adds one to the variable
- Returns the new value
If it helps to see this in code, you could think of it as
function PlusPlus(num)
{
var oldValue = num;
num = num + 1;
return oldValue;
}
Although this wouldn't actually perform the way you want it to because of pass by value, but that's besides the point. It can be tricky to remember the difference between prefix and postfix, but the main thing to remember is postfix comes AFTER the variable, and changes it AFTER everything else is done in the line, while prefix comes BEFORE the variable, and changes it BEFORE anything else is done.