Math.max()

Returns the largest of the given numbers.

Since ES1 Spec ↗

Syntax

Math.max(...values)

Parameters

NameTypeRequiredDescription
values number No Zero or more numbers to compare.

Returns

number — The largest argument, -Infinity if none given, or NaN if any argument is NaN.

Examples

console.log(Math.max(1, 5, 3));
Output
5
console.log(Math.max(...[7, 2, 9]));
Output
9

Notes

With no arguments returns -Infinity. Any non-numeric/NaN argument makes the result NaN. Spread an array to find its max: `Math.max(...arr)`.

Browser & runtime support

EnvironmentSince version
chrome 1.0
firefox 1.0
safari 1.0
edge 12
node 0.10

See also