JavaScript - Subtraction Operator
The subtraction operator (-) subtracts one number from another.
Description
The subtraction operator - subtracts the right operand from the left. Unlike +, it always converts both operands to numbers, so '10' - 2 is 8, and non-numeric strings give NaN. Subtracting two Date objects gives the difference in milliseconds.
Because subtraction always converts to numbers, it's sometimes used to turn a numeric string into a number, but Number(value) states the intent more clearly. Booleans become 1 and 0, null becomes 0, and undefined becomes NaN, so 5 - undefined is NaN. With decimals, results can show floating point rounding, such as 0.3 - 0.1 giving 0.19999999999999998.
Subtraction also works with BigInt values, as long as both operands are BigInts. It is left-associative and has the same precedence as addition, so 10 - 2 - 3 is 5. The compound form x -= y subtracts and assigns in one step, and the unary minus, -x, negates a single value.
Properties
- Operator
-- Category
- Arithmetic
- Precedence
- 11 (1 is lowest, 18 is highest)
- Associativity
- left-to-right
Syntax
x - yExample
Browser Support
The following information will show you the current browser support for the - operator. Hover over a browser icon to see the version that first introduced support for this operator.
Desktop





Tablets & Mobile





