Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

JavaScript Math min( ) Method

  • Last Updated : 09 Jul, 2020

Below is the example of the Math min() Method.

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

  • Example:




    <script type="text/javascript">
         document.write("When  positive numbers are passed"+
                        " as parameters: " + Math.min(10, 32, 2));
    </script>
  • Output:
    When  positive numbers are passed as parameters: 2

The 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 as ingle parameter that can be used n number of times as mentioned above and described below:



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

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

Below examples illustrates the Math min() method in JavaScript:

  • Example 1:
    Input : Math.min(10, 32, 2)
    Output: 2
  • Example 2:
    Input : Math.min(-10, -32, -1)
    Output: -32
  • Example 3:
    Input : Math.min()
    Output: Infinity
  • Example 4:
    Input : Math.min(10,2,NaN)
    Output: Nan

More codes for the above method are as follows:

More codes for the above method are as follows:
Program 1: When negative numbers are passed as parameters.




<script type="text/javascript">
         document.write("Result : " + Math.min(-10, -32, -1));
</script>

Output:

Result : -32

Program 2: When no parameters are passed.




<script type="text/javascript">
         document.write("Result : " + Math.min());
</script>

Output:

Result : Infinity

Program : When NaN is passed as a parameter.




<script type="text/javascript">
         document.write("Result : " + Math.min(10,2,NaN));
</script>

Output:

Result : NaN

Supported Browsers:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari



My Personal Notes arrow_drop_up

Start Your Coding Journey Now!