Skip to main content
The - operator in Dart functions as both a binary arithmetic operator for subtraction and a prefix unary operator for numeric negation. Its behavior and precedence are determined by the arity of the expression in which it is invoked.

Binary Subtraction

When used as a binary operator, - calculates the difference between a left operand and a right operand. It operates at the additive precedence level with left-to-right associativity. In Dart’s core numeric types (int and double), the return type depends on the operands: if both are integers, the result is an int; if either is a floating-point number, the result is a double.

Unary Negation

When used as a prefix unary operator, - reverses the algebraic sign of a single numeric operand. It operates at the unary prefix precedence level, which is higher than multiplicative and additive operators.

Operator Overloading

Dart permits custom classes to override the - operator. Because the operator serves two distinct arities, Dart uses different syntax signatures to differentiate between binary subtraction and unary negation during operator overloading.
  • Binary Overload: Defined using operator - with a single parameter representing the right operand.
  • Unary Overload: Defined using the specific syntax operator unary- with empty parentheses to indicate the prefix negation.
Tired of Poor Dart Skills? Fix That With Deep Grasping!Learn More