JavaScript中带有示例的Math.abs()方法

JavaScript | Math.abs()方法 (JavaScript | Math.abs() Method)

Math operations in JavaScript are handled using functions of math library in JavaScript. In this tutorial on Math.abs() method, we will learn about the abs() method and its working with examples.

JavaScript中的数学运算是使用JavaScript中的数学库函数处理的。 在有关Math.abs()方法的教程中,我们将学习abs()方法及其示例。

Math.abs() is a function in math library of JavaScript that is used to find the absolute value of the given number.

Math.abs()是JavaScript数学库中的函数,用于查找给定数字的绝对值。

Syntax:

句法:

    Math.abs(value);

Parameter(s):

参数:

  • value – It represents the value whose absolute value to be found.

    值 –它表示要找到其绝对值的值。

Return value:

返回值:

The return type of this method is number, it returns the absolute value of the given value.

此方法的返回类型为number ,它返回给定值的绝对值。

Examples 1: Valid inputs of the method

示例1:方法的有效输入

console.log(Math.abs(98))
console.log(Math.abs(-34.56))
console.log(Math.abs("-65"))

Output

输出量

98
34.56
65

Example 2: Input values that are invalid

示例2:输入值无效

console.log(Math.abs("Include Help"))
console.log(Math.abs([45, 65, 576]))
console.log(Math.abs([]))

Output

输出量

NaN
NaN
0


翻译自: https://www.includehelp.com/code-snippets/math-abs-method-with-example-in-javascript.aspx

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值