Skip to main content

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;