Visit Mozilla.org

Core JavaScript 1.5 Reference:Global Objects:Math:max

From MDC


Contents

[edit] Summary

Returns the largest of zero or more numbers.

Method of Math

Static

Implemented in: JavaScript 1.0, NES 2.0
ECMA Version: ECMA-262

[edit] Syntax

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

[edit] Parameters

value1, value2, ... 
Numbers.

[edit] Description

Because max is a static method of Math, you always use it as Math.max(), rather than as a method of a Math object you created.

If no arguments are given, the results is -Infinity

If at least one of arguments cannot be converted to a number, the result is NaN.

[edit] Examples

[edit] Example: Using Math.max

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.

[edit] See Also

Math.min