Math.max(n1, n2, ..., nX)
Category:Math
Some apps need to know the maximum number from a collection of numbers or variables. You can call Math.max with zero, one or more parameters, depending on how many numbers you want to compare.
Examples
Example: Typical Usage
var a = Math.max(5,-2);
console.log(a);
var x=9;
var y=12;
var b = Math.max(x,y);
console.log(b);
Example: Using more than two values
var a = Math.max(5, 0, 21.5, 13, -2);
console.log(a);
Syntax
Math.max(n1, n2,..., nX);
Parameters
Name | Type | Required? | Description |
---|---|---|---|
n1, n2,..., nX | number | One or more numbers or variables to compare. |
Returns
A number representing the highest of the values given as parameters, or -Infinity if no arguments are given, or NaN if one or more arguments are not numbers.
Found a bug in the documentation? Let us know at support@code.org.