Math.pow()

翻譯不完整。 請幫助我們翻譯這篇文章!

Math.pow() 函式回傳 baseexponent 次方(幂)值,也就是 baseexponent

語法

Math.pow(base, exponent)

參數

base
基數。
exponent
要乘上 base 幾次的指數。

回傳值

A number representing the given base taken to the power of the given exponent.

敘述

由於 pow()Math 的靜態方法,you always use it as Math.pow(), rather than as a method of a Math object you created(Math 並沒有建構子)。

示例

使用 Math.pow()

// simple
Math.pow(7, 2);    // 49
Math.pow(7, 3);    // 343
Math.pow(2, 10);   // 1024
// fractional exponents
Math.pow(4, 0.5);  // 2 (4 的平方根)
Math.pow(8, 1/3);  // 2 (8 的立方根)
Math.pow(2, 0.5);  // 1.4142135623730951 (2 的平方根)
Math.pow(2, 1/3);  // 1.2599210498948732 (2 的立方根)
// signed exponents
Math.pow(7, -2);   // 0.02040816326530612 (1/49)
Math.pow(8, -1/3); // 0.5
// signed bases
Math.pow(-7, 2);   // 49 (squares are positive)
Math.pow(-7, 3);   // -343 (cubes can be negative)
Math.pow(-7, 0.5); // NaN (negative numbers don't have a real square root)
// due to "even" and "odd" roots laying close to each other, 
// and limits in the floating number precision, 
// negative bases with fractional exponents always return NaN
Math.pow(-7, 1/3); // NaN 

規範

規範 狀態 註解
ECMAScript 1st Edition (ECMA-262) Standard Initial definition. Implemented in JavaScript 1.0.
ECMAScript 5.1 (ECMA-262)
The definition of 'Math.pow' in that specification.
Standard  
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'Math.pow' in that specification.
Standard  
ECMAScript (ECMA-262)
The definition of 'Math.pow' in that specification.
Living Standard  

瀏覽器相容性

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
powChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 3Opera Full support 3Safari Full support 1WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 1Samsung Internet Android Full support 1.0nodejs Full support 0.1.100

Legend

Full support  
Full support

參見