++i returns the value of i after it has been incremented. i++ returns the value of i before the increment.
When ++ comes before its operand, it is called the "pre-increment" operator, and when it comes after it is called the post-increment operator.
This difference is only important if you are doing something with the result.
var i = 0, j = 0; alert(++i); // alerts 1 alert(j++); // alerts 0
It should be noted that even if i++ returns a value before the increment, it still returns a value after it has been converted to a number.
So,
var s = "1"; alert(typeof s++); // alerts "number" alert(s); // alerts 2, not "11" as if by ("1" + 1)
Mike samuel
source share