定義和用法 pow() 方法可返回 x 的 y 次冪的值。
語法 Math.pow(x,y)
參數 描述 x 必需。底數。必須是數字。 y 必需。冪數。必須是數字。
返回值 x 的 y 次冪。
說明 如果結果是虛數或負數,則該方法將返回 NaN。如果由於指數過大而引起浮點溢出,則該方法將返回 Infinity。
實例 在下面的例子中,我們將把 pow() 運用到不同的數字組合上: <script type="text/javascript"> document.write(Math.pow(0,0) + "<br />") document.write(Math.pow(0,1) + "<br />") document.write(Math.pow(1,1) + "<br />") document.write(Math.pow(1,10) + "<br />") document.write(Math.pow(2,3) + "<br />") document.write(Math.pow(-2,3) + "<br />") document.write(Math.pow(2,4) + "<br />") document.write(Math.pow(-2,4) + "<br />") </script> 輸出: 1 0 1 1 8 -8 16 16