Why does adding increment operator on both sides of an argument fail?
let a = 1;
ReferenceError: Invalid left-hand side expression in prefix operation
The increment operators work on variables, not on expressions. You can't increment a numeric expression:
3++ // Uncaught ReferenceError: Invalid left-hand side expression in postfix operation
The reason for this is that it must increment the value, then save it back to the variable. If you gave it any old numeric expression, what would it assign the result to?
One of the two operators will work, but it returns the result of the operation, which is an expression, not a variable:
The first operator,
a++, will increment
a, and return the result:
2. The second operator is then trying to perform the increment on the value
2, which is invalid syntax.