• JavaScript Video Tutorials

JavaScript - Math max Method



Description

This method returns the largest of zero or more numbers. If no arguments are given, the results is –Infinity.

Syntax

Its syntax is as follows −

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

Parameter Details

value1, value2, ... valueN : Numbers.

Return Value

Returns the largest of zero or more numbers.

Example

Try the following example program.

<html>   
   <head>
      <title>JavaScript Math max() Method</title>
   </head>
   
   <body>      
      <script type = "text/javascript">
         var value = Math.max(10, 20, -1, 100);
         document.write("First Test Value : " + value ); 
         
         var value = Math.max(-1, -3, -40);
         document.write("<br />Second Test Value : " + value ); 
         
         var value = Math.max(0, -1);
         document.write("<br />Third Test Value : " + value ); 
         
         var value = Math.max(100);
         document.write("<br />Fourth Test Value : " + value ); 
      </script>   
   </body>
</html>

Output

First Test Value : 100
Second Test Value : -1
Third Test Value : 0
Fourth Test Value : 100 
javascript_math_object.htm
Advertisements