JavaScript max() method

Definition and usage

max() The method returns the number with the highest value.

Tip:min() The method returns the number with the minimum value.

Instance

Example 1

The largest return value:

Math.max(5, 10);

Try it yourself

Example 2

The highest return value:

var a = Math.max(5, 10);
var b = Math.max(0, 150, 30, 20, 38);
var c = Math.max(-5, 10);
var d = Math.max(-5, -10);
var e = Math.max(1.5, 2.5);

Try it yourself

Syntax

Math.max(n1, n2, n3, ... , nX)

Parameter value

Parameter Description
n1, n2, n3, ... , nX Optional. One or more numbers to be compared.

Technical details

Return value:

A number, representing the maximum value in the parameter.

  • If no parameters are provided, it returns -Infinity.
  • If one or more of the parameters are not numbers, then it returns NaN.
JavaScript Version: ECMAScript 1

Browser Support

Method Chrome IE Firefox Safari Opera
max() Support Support Support Support Support

Related Pages

Tutorial:JavaScript Math