comparison

Math.min

Returns the smallest of zero or more numbers passed as separate arguments. With no arguments returns +Infinity.

Math.min(...values)

Parameters & edge cases

Case Behavior
...values Any number of numeric arguments (0 or more)
no args Math.min() returns +Infinity (the identity for the min operation)
NaN input Any NaN makes the result NaN
clamp idiom Math.min(max, Math.max(min, x)) clamps x into [min, max]

Examples

console.log(Math.min(1, 2, 3));       // 1

Straightforward variadic min.

console.log(Math.min());              // Infinity

No args returns +Infinity.

console.log(Math.min(...[3, 1, 2])); // 1

Spread an array to pass its items as arguments.

console.log(Math.min(Math.max(0, x), 100)); // clamp x to [0,100]

The canonical clamp idiom.

Gotcha

As with Math.max, spreading giant arrays can overflow the argument stack. Consider a reduce loop for arrays larger than ~100k items.

Related

← All JS Math methods · Array methods