Unary expressions invoke unary operators on objects.
A unary postfix expression is an invocation of a postfix operator on an expression.
The Postfix increment operator (++
) is to increase the operand`s value by one unit.
Example:
var x = 0;
print(x++); // x = x + 1 (expression value is x)
Example:
var x = 0;
var y = 0;
x = 0;
y = x++; // Increment x AFTER y gets its value.
print(x != y); // 1 != 0
The Postfix decrement operator (--
) is to decrease the operand`s value by one unit.
Example:
var x = 0;
print(x--); // x = x - 1 (expression value is x)
Example:
var x, y;
x = 0;
y = x--; // decrement x AFTER y gets its value.
assert(x != y); // -1 != 0