Math.min()

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

							math.min(num1, num2)
						

Description

The min() method of the Math object gets the minimum number of the two number parameters passed to it. The smaller value is returned as the result.

Example

Listing 6.167 shows how to use the Math.min() method.

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

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.