此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

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 ⁨2015年7月⁩.

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® 2026 Language Specification
# sec-math.pow

浏览器兼容性

参见