【JavaScript Math max()方法使用介绍】以下是示例数学最大值方法。
- 例子: filter_none
编辑
关
play_arrow
链接
亮度_4
代码
< script type= "text/javascript" > document.write( "When positive numbers are passed" + " as parameters: " + Math.max(10, 32, 2)); < /script>
chevron_right
filter_none
- 输出如下:
Whenpositive numbers are passed as parameters: 32
max()是Math的静态方法, 因此, 始终将其用作Math.max(), 而不是用作创建的Math对象的方法。
语法如下:
Math.max(value1, value2, ...)
参数:此方法接受ingle参数, 如上所述, 该参数可以使用n次, 如下所述:
- 值:此值发送到math.max()找到最大的方法。
以下示例说明了JavaScript中的Math max()方法:
- 范例1:
Input : Math.max(10, 32, 2)Output: 32
- 范例2:
Input : Math.max(-10, -32, -1)Output: -1
- 范例3:
Input : Math.max()Output: -Infinity
- 范例4:
Input : Math.max(10, 2, NaN)Output: NaN
程序1:
当传递负数作为参数时。
<
script type= "text/javascript" >
document.write( "Result : " + Math.max(-10, -32, -1));
<
/script>
输出如下:
Result : -1
程式2:没有参数传递时。
<
script type= "text/javascript" >
document.write( "Result : " + Math.max());
<
/script>
输出如下:
Result : -Infinity
程序:NaN作为参数传递时。
<
script type= "text/javascript" >
document.write( "Result : " + Math.max(10, 2, NaN));
<
/script>
输出如下:
Result : NaN
支持的浏览器:
- 谷歌浏览器
- IE浏览器
- 火狐浏览器
- 歌剧
- 苹果浏览器
推荐阅读
- C#类和对象用法详细指南
- PHP Ds PriorityQueue pop()函数用法介绍
- PHP | getprotobyname()函数用法介绍
- C++标准模板库(STL)中的队列用法介绍
- npm项目配置中文参考文档
- npm命令行中文参考文档详解
- node命令行大全详解
- 在package.json文件scripts自定义脚本命令,简化webpack打包命令
- Node.js非阻塞IO模型、异步调用、事件驱动、回调函数和EventEmitter