The LeftHandSideExpression operator for the ++ operator must not be a number. For example,
1++;
will fail with the same error (invalid increment operand). You can only use pre- and postincrement statements for variables / identifiers / expressions.
Since the + sign distinguishes null value from the number (0), you get the same result.
Examples:
var foo = null, bar = 5; foo++; // 0 0++; // invalid increment operand null++; // invalid increment operand (+bar)++ // invalid increment operand foo++ +2; // 2
jAndy
source share