ES6 - Math Abs() 函式



此方法返回數字的絕對值。

語法

Math.abs( x ) ;     

引數

  • X − 代表一個數字

返回值

返回數字的絕對值

示例

console.log("---Math.abs()---") 
console.log("Math.abs(-5.5) : "+Math.abs(-5.5)) 
console.log("Math.abs(5.5) : "+Math.abs(5.5))         

輸出

---Math.abs()--- 
Math.abs(-5.5) : 5.5 
Math.abs(5.5) : 5.5          
廣告
© . All rights reserved.