+ 2
What is unary +?
3 Respuestas
+ 8
The unary plus in itself doesn't do anything because multiplying anything by +1 won't change the result.
E.g
var = 10
var2 = -20
+var would yield 10
+var2 yields -20
The result is unchanged.
It is only used in a certain scenario in which it does make a difference.
The unary minus on the other hand does change the result, because -1 multiplied with another operand does change the result. If the operand is positive, it makes it negative. If the operand is negative, yields a positive version.
E.g
var = 2
var2 = -4
-var yields -2
-var2 yields 4
To round up your question, the unary + is used to prefix a variable in order to multiply the value by +1. The use of it however is not needed.
0
Thanks Gershon
0
(+1)
(-2)
unary operator operates over one number only