Home > Web Front-end > JS Tutorial > How to find the maximum value of three numbers in javascript

How to find the maximum value of three numbers in javascript

青灯夜游
Release: 2021-10-20 15:05:19
Original
6778 people have browsed it

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)”.

How to find the maximum value of three numbers in javascript

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)
Copy after login

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));
Copy after login

How to find the maximum value of three numbers in javascript

[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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template