Unary Expressions
Last modified: September 5, 2024
Introduction
An unary minus operator is used to convert a number from negative to positive or vice versa.
There is no unary plus.
Example
The example below represents the negative value of 8
.
-8
When used with a variable that already has a negative value the result is positive.
For example, if $myVariable
has the integer value -7
:
-$myVariable
The output is:
7