ES6 - Math sqrt() 函式



此方法返回數字的平方根。如果數字的值為負數,則 sqrt 返回 NaN。

語法

Math.sqrt ( x );  

引數

  • x − 表示一個數字

返回值

返回數字的平方根。

示例

console.log("---Math.sqrt()---") 
console.log("Math.sqrt(16) : "+Math.sqrt(16) 
console.log("Math.sqrt(15.5) : "+Math.sqrt(15.5))           

輸出

---Math.sqrt()--- 
Math.sqrt(16) : 4 
Math.sqrt(15.5) : 3.9370039370059056             
廣告