Favorites

JavaScript Math.max() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Math.max()
JavaScript Math Static methodThis method is supported by all modern browsers.
Updated 28th November 2026

The Math.max() static method returns the largest of the numbers passed to it. Spread an array into it to find the array's maximum.

Description

The Math.max() static method returns the largest of its arguments. To find the maximum of an array, spread it: Math.max(...arr). With an empty array this returns -Infinity, and with very large arrays (hundreds of thousands of elements) spreading can exceed the argument limit, in which case a loop or reduce() is safer.

Combined with Math.min(), it clamps a value into a range: Math.min(Math.max(value, min), max).

If any argument is NaN, or can't be converted to a number, the result is NaN. Arrays can't be passed directly; Math.max([1, 2]) converts the array to a string first and gives NaN, which is why spreading is needed.

Syntax

Math.max(value1, value2, ...)

Parameters

  • value1, value2, ...Numbers to compare.

Return Value

The largest number, -Infinity with no arguments, or NaN if any argument can't be converted to a number.

Example

console.log(Math.max(3, 17, 9));
const temps = [22, 31, 18];
console.log(Math.max(...temps));
console.log(Math.max());
const clamp = (v, lo, hi) => Math.min(Math.max(v, lo), hi);
console.log(clamp(120, 0, 100));

Browser Support

The following information will show you the current browser support for the Math.max() method. Hover over a browser icon to see the version that first introduced support for this method.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee