Math.max() In JavaScript
The Math.max() function is used to return the largest of zero or more numbers.
The result is “-Infinity” if no arguments are passed and the result is NaN if at least one of the arguments cannot be converted to a number.
max() is a static method of Math, therefore, it is always used as Math.max(), rather than as a method of a Math object created.
Syntax:
Math.max(value1, value2, ...)
Parameters Used:
Value1,Value2 :Values sent to math.max() function for finding the largest.
Return Value:
The Math.max() function returns the largest of the given numbers.
Examples:
Input : Math.max(10, 32, 2)
Output : 32
Input : Math.max(-10, -32, -1)
Output : -1
Input : Math.max()
Output : -Infinity
Input : Math.max(10,2,NaN)
Output : Nan
- When positive numbers are passed as parameters.
<scripttype="text/javascript">document.write("Output : " + Math.max(10, 32, 2));</script>chevron_rightfilter_noneOutput:
Output : 32
- When negative numbers are passed as parameters.
<scripttype="text/javascript">document.write("Output : " + Math.max(-10, -32, -1));</script>chevron_rightfilter_noneOutput:
Output : -1
- When no parameters are passed.
<scripttype="text/javascript">document.write("Output : " + Math.max());</script>chevron_rightfilter_noneOutput:
Output : -Infinity
- When NaN is passed as a parameter.
<scripttype="text/javascript">document.write("Output : " + Math.max(10,2,NaN));</script>chevron_rightfilter_noneOutput:
Output : NaN
Recommended Posts:
- Map.has( ) In JavaScript
- JavaScript | Let
- Map.get( ) In JavaScript
- Map in JavaScript
- this in JavaScript
- Atomics.xor() In JavaScript
- JavaScript JSON
- JavaScript | Performance
- JavaScript | Callbacks
- JavaScript | weakMap.get()
- Atomics.and() In JavaScript
- console in JavaScript
- JavaScript | Hoisting
- JavaScript | Comments
- JavaScript | typedArray.some() with Example
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



