Unary - — numeric negation

Syntax and values

Behavior and details

A unary operator works with one value. Unary - reverses a Number’s sign: -5 is negative five, and -(-5) gives five. It can also act on a variable or a grouped expression.

This differs from the two-value subtraction in 8 - 3. Several unary operators group from the right: - -5 means -(-5). When a function’s first argument starts with a sign, use call parentheses, such as say(-5).

Example

# language: en
let value = 3
say(-value)
say(-(2 + 3))

Syntax and values · Built-ins · Programming guides