max

Returns the larger of two numbers.

Applies to

Math

Syntax

max(x,y)

Parameters

x,y

Numbers.

Description

max is a static method of Math. As a result, you always use it as Math.max(), rather than as a method of a Math object you create.

Examples

The following function evaluates the variables x and y:

function getMax(x,y) {
      return Math.max(x,y)
}

If you pass getMax the values 10 and 20, it returns 20; if you pass it the values -10 and -20, it returns -10.

See also

Math.min