comparison

Math.max

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

Math.max(...values)

Parameters & edge cases

Case Behavior
...values Any number of numeric arguments (0 or more)
no args Math.max() returns -Infinity (the identity for the max operation)
NaN input Any NaN argument makes the result NaN
arrays Spread with Math.max(...arr); huge arrays can hit call-stack limits

Examples

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

Straightforward variadic max.

console.log(Math.max());              // -Infinity

No args returns -Infinity so that max(a, Math.max()) === a.

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

Spread an array — required because Math.max([1,2,3]) returns NaN.

console.log(Math.max(1, NaN));        // NaN

NaN is contagious; filter with .filter(Number.isFinite) first.

Gotcha

For arrays over ~10⁵ elements, Math.max(...arr) can throw a RangeError. Use `arr.reduce((a, b) => a > b ? a : b)` for very large arrays.

Related

← All JS Math methods · Array methods