Home > Web Front-end > JS Tutorial > body text

How to find the minimum value in javascript

青灯夜游
Release: 2021-06-18 17:04:12
Original
4996 people have browsed it

In JavaScript, you can use the min() method of the Math object to find the minimum value. This method can return the minimum value among zero or more values. The syntax format is "Math.min(value 1, value 2, value 3,..., value N) "; if any parameter cannot be converted to a numerical value, "NaN" is returned.

How to find the minimum value in javascript

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

In javascript, you can use the min() method of the Math object to find the minimum value.

Let’s learn about it through an example:

console.log(Math.min(5,10));
console.log(Math.min(0,150,30,20,38));
console.log(Math.min(-5,10));
console.log(Math.min(-5,-10));
console.log(Math.min(1.5,2.5));
Copy after login

Output:

How to find the minimum value in javascript

Explanation:

Math.min() Returns the minimum of zero or more values.

Syntax

Math.min(n1,n2,n3,...,nX)
Copy after login

Return value:

  • The smallest number among the given values.

Description:

Since min is a static method of Math, it should be used like this: Math.min(), not as a method of the Math instance you created (Math is not a constructor).

If there are no parameters, the result is Infinity.

If any parameter cannot be converted to a numeric value, the result is NaN.

[Related recommendations: javascript learning tutorial]

The above is the detailed content of How to find the minimum value 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!