The Wayback Machine - https://web.archive.org/web/20241217203858/https://www.geeksforgeeks.org/javascript-math-min-method/
Open In App

JavaScript Math min() Method

Last Updated : 15 Jul, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

The JavaScript Math min( ) Method is used to return the lowest-valued number passed in the method. The Math.min() method returns NaN if any parameter isn’t a number and can’t be converted into one. The min() is a static method of Math, therefore, it is always used as Math.min(), rather than as a method of a Math object created. 

Syntax:

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

Parameters:

This method accepts a single parameter that can be used n number of times as mentioned above and described below:

  • value: These values are sent to math.min() method for finding the largest.

Return Value:

The Math.min() method returns the smallest of the given numbers.

Example 1: Below are examples of the Math min() Method.

javascript
console.log("When positive numbers are passed" +
    " as parameters: " + Math.min(10, 32, 2));

Output
When positive numbers are passed as parameters: 2

Example 2: When negative numbers are passed as parameters. 

javascript
console.log("Result : " + Math.min(-10, -32, -1));

Output
Result : -32

Example 3: When no parameters are passed.

javascript
console.log("Result : " + Math.min());

Output:

Result : Infinity

Example 4: When NaN is passed as a parameter.

javascript
console.log("Result : " + Math.min(10,2,NaN));

Output:

Result : NaN

We have a complete list of Javascript Math Objects methods, to check those please go through this Javascript Math Object Complete reference article.

Supported Browsers

  • Chrome 51
  • Edge 15
  • Firefox 54
  • Safari 10
  • Opera 38

JavaScript Math min() Method – FAQs

What does the Math.min() method do in JavaScript?

The Math.min() method returns the smallest of zero or more numbers provided as arguments.

Can Math.min() handle negative numbers?

Yes, Math.min() can handle negative numbers. It returns the smallest value among all the arguments, whether they are positive or negative.

How does Math.min() handle non-numeric arguments?

If any of the arguments are non-numeric and cannot be converted to a number, Math.min() returns NaN (Not-a-Number).

Can Math.min() be used with arrays or objects?

No, Math.min() directly accepts numeric arguments. To find the minimum value in an array, you can use the spread operator or apply() to pass elements as individual arguments: Math.min(…array).

What is the most common use of the Math.min() method?

Most Common Use Cases:

  • Determining the lowest score in a set of game scores.
  • Finding the smallest dimension (length, width, height) among objects.
  • Implementing sorting algorithms or custom comparisons.
  • Calculating the minimum value in a set of data points for statistical analysis.

    We have a Cheat Sheet on Javascript where we covered all the important topics of Javascript to check those please go through Javascript Cheat Sheet-A Basic guide to JavaScript.


    Next Article

    Similar Reads

    three90RightbarBannerImg