JavaScript Tutorial JavaScript References

JavaScript - Math.min() Method



The JavaScript Math.min() method returns the lowest-valued number passed into it, or NaN if any parameter is not a number and can not be converted into a number.

Syntax

Math.min(value1, value2, ...)

Parameters

value1, value2, ... Specify zero or more numbers among which the smallest value need to be returned.

Return Value

Returns the smallest of the given numbers, or NaN if any parameter is not a number and can not be converted into a number.

Example:

In the example below, Math.min() method is used to find out the smallest of the given numbers.

var txt;

txt = "Math.min(10, 30, 20, 10, 90) : " + 
               Math.min(10, 30, 20, 10, 90) + "<br>";

txt = txt + "Math.min('10', '30', '20', '10') : " + 
               Math.min('10', '30', '20', '10') + "<br>";

txt = txt + "Math.min('10', '30', 20, '10') : " + 
               Math.min('10', '30', 20, '10') + "<br>";

txt = txt + "Math.min('10', 'x', 20, '10') : " + 
               Math.min('10', 'x', 20, '10') + "<br>";

The output (value of txt) after running above script will be:

Math.min(10, 30, 20, 10, 90) : 10
Math.min('10', '30', '20', '10') : 10
Math.min('10', '30', 20, '10') : 10
Math.min('10', 'x', 20, '10') : NaN

❮ JavaScript - Math Object