Math.max

Category:Math

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

Category: Math

Returns the maximum value among one or more values n1, n2, ..., nX.

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


var a = Math.max(5,-2);
console.log(a);
var x=9;
var y=12;
var b = Math.max(x,y);
console.log(b);

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 No 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 documentation@code.org

Found a bug in the documentation? Let us know at documentation@code.org