JavaScript (ES2026) reference · Math Methods and Constants
JavaScript Math.max() Method
Return the largest of the given numbers. Use the spread syntax to find the largest value in an array.
JavaScript (ES2026) Since ES1
Syntax
Math.max(value1, value2, /* …, */ valueN)
Parameters
| Parameter | Description |
|---|---|
values |
Numbers to compare. |
Return value
The largest number, -Infinity with no arguments.
Examples
console.log(Math.max(3, 9, 4));
const temps = [12, 25, 18];
console.log(Math.max(...temps));
Output
9 25
console.log(Math.max(), Math.max(1, "x"));
Output
-Infinity NaN
Version history
| Version | Change |
|---|---|
| JavaScript ES1 | Added |
In other languages
max()· Python
Related
Math.min()· Return the smallest of the given numbers. Use spread to find the smallest value in an array.- JavaScript Math · tutorial
- JavaScript Numbers · tutorial