Math.max() Method - Math Functions

Math.max() method of Math Functions in Javascript.
How to get the highest valued number in javascript?

Explanation

Object: Math
Method: Math.max()
Description: To get the max valued number or the highest number out of a set of numbers. The below example will get the highest value from the inputed numbers using Math Functions.

Example:


<html>
<script type="text/javascript">
function maxnum()
{
var one=document.frm.num1.value;
var two=document.frm.num2.value;
alert('Maximum value is::'+ Math.max(one,two));
}
</script>
<form name=frm>
First Number :<input type="text" name="num1" size=10>
<br><br>
Second Number :<input type="text" name="num2" size=10>
<br>
<input type="button" value="Show Max number" onClick="maxnum()">
</form>
</html>

Result:


First Number :
Second Number :


In the above example,
  • Using a form two numbers are got as input.
  • Math.max() function is used to get the highest out of the two numbers.

Ask Questions

Ask Question