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