max()  Math  class method JS Home  <<  JS Reference  <<  Math  <<  max()

Description

Returns the largest of some numbers.

  • Like all class methods max() should be used on the class rather than an instance of the class.

Syntax

Signature Description
Math.max([value1 [,value2[ ,...valueN]]])Returns the largest of some numbers.

Parameters

Parameter Description
value1, value2, ...valueNThe values you wish to find the largest number of:
  • Non-numeric strings returns NaN.
  • Passing no parameter returns NaN.
  • Passing null returns 0.

Examples

The code below displays max() usage.


// Store results in an array.
var maxValues = new Array(6);

maxValues[0] = Math.max(1.9, 1.6, 1.90001);
maxValues[1] = Math.max(-10.8, -10.6, -10.59);
maxValues[2] = Math.max('100.1', '100.2', '101');
maxValues[3] = Math.max('five', 6, 7);
maxValues[4] = Math.max();
maxValues[5] = Math.max(null, null);

alert(maxValues);  

Press the button below to action the above code:

Related Tutorials

JavaScript Advanced Tutorials - Lesson 4 - Math