Math.pow()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

Math.pow() 函数返回基数(base)的指数(exponent)次幂,即 base^exponent

尝试一下

console.log(Math.pow(7, 3));
// Expected output: 343

console.log(Math.pow(4, 0.5));
// Expected output: 2

console.log(Math.pow(7, -2));
// Expected output: 0.02040816326530612
//                  (1/49)

console.log(Math.pow(-7, 0.5));
// Expected output: NaN

语法

Math.pow(base, exponent)

参数

base

基数

exponent

指数

描述

由于 powMath 的静态方法,所以应该像这样使用:Math.pow(),而不是作为你创建的 Math 对象的方法。

示例

使用 Math.pow

js
function raisePower(x, y) {
  return Math.pow(x, y);
}

如果 x 是 2,且 y 是 7,则 raisePower 函数返回 128(2 的 7 次幂)。

规范

Specification
ECMAScript® 2025 Language Specification
# sec-math.pow

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
pow

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

参见