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

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

Math.max(value1, value2, /* …, */ valueN)

Parameters

ParameterDescription
values Numbers to compare.

Return value

The largest number, -Infinity with no arguments.

Examples

Largest valueTry it yourself
console.log(Math.max(3, 9, 4));
const temps = [12, 25, 18];
console.log(Math.max(...temps));

Output

9
25
No arguments, or a non-numberTry it yourself
console.log(Math.max(), Math.max(1, "x"));

Output

-Infinity NaN

Version history

VersionChange
JavaScript ES1Added

In other languages

Was this page helpful?