Home>Article>Web Front-end> How to use max function

How to use max function

不言
不言 Original
2019-02-16 16:24:37 21040browse

The max function can be used to return the largest value among multiple numbers. The syntax of this function is "Math.max(value1, value2,...)", where if no parameters are passed, the result is "-Infinity", if at least one argument cannot be converted to a number, the result is NaN.

How to use max function

The operating environment of this article: Windows 7 system, Dell G3 computer, javascript1.8.5.

The max function can be used to return the largest value among multiple numbers. If no parameters are passed, the result is "-Infinity". If at least one parameter cannot be converted to a number, the result is NaN. Let's take a look at the specific use of the max function.

Let’s first look at the basic syntax of the max function

Math.max(value1,value2,...)

Value1, Value2,...: The values passed to the math.max() function are used to find the maximum value.

Let’s look at specific examples

When the parameters are positive and negative numbers:

The code is as follows

     

Execution results As follows:

Output : 32 Output : -1

When no parameters are passed

The code is as follows:

     

The execution result is as follows

Output : -Infinity

When there are parameters in the parameters that cannot be converted to numbers:

The code is as follows

     

The execution result is as follows

Output : NaN

This article ends here It's all over. For more exciting content, you can pay attention to other related column tutorials on the PHP Chinese website! ! !

The above is the detailed content of How to use max function. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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
Previous article:How to use sqrt function Next article:How to use sqrt function