Math.max()
Returns the largest of the given numbers.
Syntax
Math.max(...values) Parameters
| Name | Type | Required | Description |
|---|---|---|---|
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
| Environment | Since version |
|---|---|
| chrome | 1.0 |
| firefox | 1.0 |
| safari | 1.0 |
| edge | 12 |
| node | 0.10 |