docs/reference/compat/math/subtract.md
::: warning Use - operator
This subtract function works slowly due to additional function calls.
Use the faster and simpler - operator instead.
:::
Subtracts two numbers.
const result = subtract(value, other);
subtract(value, other)Use subtract when you want to subtract two numbers.
import { subtract } from 'es-toolkit/compat';
// Basic subtraction
subtract(6, 4);
// Returns: 2
subtract(10, 3);
// Returns: 7
// Negative number handling
subtract(-6, 4);
// Returns: -10
subtract(6, -4);
// Returns: 10
// NaN handling
subtract(NaN, 4);
// Returns: NaN
subtract(6, NaN);
// Returns: NaN
subtract(NaN, NaN);
// Returns: NaN
value (number): The base number for subtraction.other (number): The number to subtract.(number): Returns the result of subtracting the second number from the first. If either is NaN, returns NaN.