How to use the max in JavaScript

In this article we will discuss about how to use the max() method in JavaScript
  • 1572

This method is used to return the maximum value among all 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 max() method of Math is is as follows:

Syntax:

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

JavaScript Code:

<html>

<head>

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

</head>

<body>

    <script type="text/javascript">

 

        var maxvalue = Math.max(100, 200, -2, 1000);

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

 

        var maxvalue = Math.max(-4, -2, -50);

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

 

        var maxvalue = Math.max(0, -3);

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

 

        var maxvalue = Math.max(100);

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

    </script>

</body>

</html>

Output:

java3.jpg

Ask Your Question 

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

Programming Answers here

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.