Javascript - Math max() Method

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

Description

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

Syntax

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

Parameter Values

ParameterRequire Description
n1, n2, n3, ..., nX Optional. One or more numbers to compare

Return

A Number, representing the highest number of the arguments

-Infinity if no arguments are given

NaN if one or more arguments are not numbers

Example

Return the number with the highest value:

Demo

//return the highest number of 5 and 10.
console.log(Math.max(5, 10));//from   w  w w  . j ava 2s.  c o m

//Return the number with the highest value:
var a = Math.max(5, 10);
var b = Math.max(0, 150, 30, 20, 38);
var c = Math.max(-15, 10);
var d = Math.max(-15, -10);
var e = Math.max(1.15, 2.5);

var x = a + "\n" + b + "\n" + c + "\n" + d + "\n" + e;
console.log(x);

Result