Computer >> Computer tutorials >  >> Programming >> Javascript

How to get the smallest of zero or more numbers in JavaScript?


To get the smallest of zero or more number in JavaScript, use the Math.max() method. If no arguments are given, the results is -Infinity.

Syntax

The following in the syntax −

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

The parameter value1, value, … value N numbers.

Example

You can try to run the following code to get the smallest of zero or more numbers −

<html>
   <head>
      <title>JavaScript Math min() Method</title>
   </head>
   <body>
     <script>
         var value = Math.min(30, 100, -50, 90);
         document.write("First Value : " + value );
         
         value = Math.min(0, -1);
         document.write("<br />Second Value: " + value );
      </script>
   </body>
</html>