Home >Web Front-end >JS Tutorial >How to find the maximum value of three numbers in javascript
In JavaScript, we can use the max() method of the Math object to find the maximum value of three numbers. The function of this method is to calculate the maximum value between multiple values and return it; the syntax "Math. max(n1,n2,n3)”.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
In JavaScript, if you want to find the maximum value in a series of numbers, you can use the Math.max()
method.
The max() method returns the number with the larger value among multiple specified numbers. (Before ECMASCript v3, this method had only two parameters)
Syntax format:
Math.max(n1,n2,n3,...,nX)
Return value: The largest value among multiple parameters can be returned. If there are no arguments, -Infinity is returned. If an argument is NaN, or a non-numeric value that cannot be converted to a number, NaN is returned.
Example:
console.log(Math.max(5,10,2)); console.log(Math.max(150,30,20)); console.log(Math.max(-5,-10,-1)); console.log(Math.max(-5,-1,2)); console.log(Math.max(1.5,2.5,1));
[Recommended learning: javascript advanced tutorial】
The above is the detailed content of How to find the maximum value of three numbers in javascript. For more information, please follow other related articles on the PHP Chinese website!