Aller au contenu principal

subtract()

subtract(minuend, subtrahend): number

Subtracts two numbers.

DEPRECATED

Use the - operator directly instead.


Parameters

minuend: number

The first number in a subtraction.

subtrahend: number

The second number in a subtraction.


Returns: number

The difference.


See Also

Subtraction (-) - MDN


Since

2.0.0


Also known as

subtract (Lodash, Ramda) · ❌ (es-toolkit, Remeda, Radashi, Effect, Modern Dash, Antfu)


Example

// ❌ Deprecated approach
subtract(6, 4); // => 2

// ✅ Recommended approach
6 - 4; // => 2

How it works?

Subtracts two numbers. Deprecated: Use the - operator directly.

Native Equivalent

// ❌ subtract(6, 4)
// ✅ 6 - 4

Use Cases

Subtract numbers 📌

Subtract two numbers.

a - b;

Calculate difference

Calculate change between values.

const change = newValue - oldValue;
const percentChange = (change / oldValue) * 100;