Math

Math.max

Returns the largest of zero or more numbers

Syntax

JavaScript
Math.max(...values)

Parameters

ParameterTypeDescription
valuesnumber[]Zero or more numbers

Return Value

The largest of the given numbers, or -Infinity if no arguments

Examples

Basic Usage
console.log(Math.max(1, 3, 2)); // 3
console.log(Math.max(-1, -3, -2)); // -1
Practical Example
const scores = [88, 92, 75, 95, 81];
const highest = Math.max(...scores);
console.log(highest); // 95
Advanced Usage
console.log(Math.max()); // -Infinity
console.log(Math.max(10)); // 10

Understanding Math.max

The Math.max method in JavaScript returns the largest of zero or more numbers. It belongs to the Math object and is one of the most widely used methods for working with math values in modern JavaScript and TypeScript applications.

The method signature is Math.max(...values). It accepts 1 parameter: values. When called, it returns the largest of the given numbers, or -infinity if no arguments. Understanding when and how to use max() helps you write more expressive, readable code.

Common use cases for Math.max include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like math-min, math-abs, enabling you to chain operations together for complex data manipulation pipelines.

Browser support for Math.max is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.

Browser Compatibility

Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.

Related Methods

More Math Methods

Other methods in the Math object

Related Tools

More Math Methods

Explore JavaScript Methods

Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.