Math.max()

JavaScript 1.0+, ECMAScript 1.0+, JScript 1.0+ Nav2+, NES2+, IE3+, Opera3+ Syntax

							math.max(num1, num2)
						

Description

The max() method of the Math object gets the maximum number of the two parameters passed to it. The larger value is returned as the result.

Example

Listing 6.166 shows how the max() method is used to get the larger of two values.

Listing 6.166 Example of the max() Method
 <html> <body> <script language="JavaScript"> <!–– Hide // function returns the maximum of two arguments function doMath(){ var inputNum1=document.form1.input1.value; var inputNum2=document.form1.input2.value; var result = Math.max(inputNum1, inputNum2); document.form1.answer.value = result; } // End Hide ––> </script> <form name=form1> This example ...

Get Pure JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.