DEV Community

Anna
Anna

Posted on

Unary operators in Javascript Objects

A unary operator is an operation with only one operand.

Plus sign (+) can function as an Addition Operator and also as a Unary Version in Javascript Objects.

As an arithmetic addition operator: It takes numerical values (literals or variables) as their operands and return a single numerical value.

Both + and - operators have unary versions, where they operate only on one variable.
When used in this fashion, + returns the number representation of the object, while - returns its negative counterpart

The unary plus operator converts its operand to Number type.

The unary negation operator converts its operand to Number type and then negates it.

Top comments (1)

Collapse
 
hackyfuturebe profile image
HackYourFuture Belgium

Thank you for sharing, Anna!