JavaScript Math min()

The min() method finds the minimum value among the specified values and returns it.

Example


min() Syntax

The syntax of the min() method is:

Math.min(number1, number2,....)

Here, min() is a static method. Hence, we are accessing the method using the class name, Math.


min() Parameters

The min() method takes in a random number of parameters:

  • number1/number2/… - values among which the minimum number is to be computed

min() Return Value

The min() method returns:

  • the smallest value among the given numbers
  • NaN (Not a Number) for non-numeric arguments

Example 1: JavaScript Math.min()

In the above example, we have used Math.min() to find the minimum number among:

  • Math.min(-1,-11,-132) - returns -132
  • Math.min(0.456,135,500) - returns 0.456

Example 2: Math.min() with Arrays

In the above example, we have created an array named numbers. Notice that we are passing the array as an argument to the Math.min() method.

let minNum = Math.min(...numbers);

Here, ... is the spread operator that destructures the array and passes the array values as arguments to min().

The method then finds the smallest number.


Example 3: Math.min() with Non-Numeric Argument

In the above example, we have used the min() method with the string and character arguments. For both arguments, we get NaN as output.


Recommended readings: