Math min() and max() Methods

The min() and max() methods determine which number is the smallest or largest in a group of numbers. These methods accept any number of parameters:

 
<!DOCTYPE html>
<html>
<head>
    <title>Example</title>
    <script type="text/javascript">

        var max = Math.max(3, 5, 3, 6); 
        document.writeln(max); // 6
    
        var min = Math.min(3, 5, 3, 6); 
        document.writeln(min); //3 

    </script>
</head>
<body>
</body>
</html>
  
Click to view the demo

To find the maximum or the minimum value in an array, you can use the apply() method as follows:

 
<!DOCTYPE html>
<html>
<head>
    <title>Example</title>
    <script type="text/javascript">
            var values = [1, 2, 3, 4, 5, 6, 7, 8]; 
            var max = Math.max.apply(Math, values); 
            document.writeln(max);//8
    </script>
</head>
<body>
</body>
</html>
  
Click to view the demo
Home 
  JavaScript Book 
    Essential Types  

Math:
  1. The Math Object
  2. Math min() and max() Methods
  3. Math.ceil()
  4. Math.floor()
  5. Math.round()
  6. random() Method