How to use min in JavaScript

In this article we will discuss about How to use min() method in JavaScript.
  • 1741

This method is used to return the minimum value among the values given to it. If we will not pass any type of argument to it then it will return the infinity as a result. the Syntax of using the min() method of Math is is as follows:

Syntax:

Math.min(value 1,value 2,............. value n);

Here min method has been passed some values like value1, value2.........value n from which it will select the minimum means smallest value.

JavaScript Code:

<html>

<head>

    <title>JavaScript Math min() Method</title>

</head>

<body>

    <script type="text/javascript">

 

        var minumber = Math.min(1, 2, -2, 10);

        document.write("First Test Value : " + minumber);

 

        var minumber = Math.min(-4, -3, -30);

        document.write("<br />Second Test Value : " + minumber);

 

        var minumber = Math.min(0, -1);

        document.write("<br />Third Test Value : " + minumber);

 

        var value = Math.min(100);

        document.write("<br />Fourth Test Value : " + minumber);

    </script>

</body>

</html>

Output:

java1.jpg

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.