このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docsコミュニティーについてもっと知り、仲間になるにはこちらから。
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() は静的メソッドで、基数をべき乗した値を返します。
In this article
試してみましょう
console.log(Math.pow(7, 3));// 予想される結果: 343console.log(Math.pow(4, 0.5));// 予想される結果: 2console.log(Math.pow(7, -2));// 予想される結果: 0.02040816326530612// (1/49)console.log(Math.pow(-7, 0.5));// 予想される結果: NaN構文
js
Math.pow(base, exponent)引数
返値
base を表す数値をexponent 乗した値。以下のいずれかの場合は、NaN を返します。
exponentがNaNである。baseがNaNで、exponentが0以外である。baseが ±1 で、exponentが ±Infinityである。base < 0で、exponentが整数ではない。
解説
Math.pow() は** 演算子と同等ですが、Math.pow() は数値のみを受け入れるという点が異なります。
Math.pow(NaN, 0)(および同等のNaN ** 0)は、NaN が数学演算で伝播しない唯一のケースです。これは、オペランドがNaN であるにもかかわらず1 を返します。さらに、base が 1 でexponent が無限大(±Infinity またはNaN)である場合の動作は、結果が 1 となることを規定している IEEE 754 とは異なり、 JavaScript では元の動作との後方互換性を維持するためにNaN を返します。
pow() はMath の静的メソッドなので、常にMath.pow() として使用し、自分でMath オブジェクトを生成してそのメソッドとして使用しないでください。 (Math にはコンストラクターがありません)。
例
>Math.pow() の使用
js
// 基本的な例Math.pow(7, 2); // 49Math.pow(7, 3); // 343Math.pow(2, 10); // 1024// 小数のべき乗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 の立方根)// 負の数のべき乗Math.pow(7, -2); // 0.02040816326530612 (1/49)Math.pow(8, -1 / 3); // 0.5// 負の数の底Math.pow(-7, 2); // 49 (2 乗は正の数)Math.pow(-7, 3); // -343 (3 乗は負の数)Math.pow(-7, 0.5); // NaN (負の数には実数の平方根がない)// 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,// even when the mathematical result is realMath.pow(-7, 1 / 3); // NaN// Zero and infinityMath.pow(0, 0); // 1 (任意の数 ** ±0 is 1)Math.pow(Infinity, 0.1); // Infinity (正の指数)Math.pow(Infinity, -1); // 0 (負の指数)Math.pow(-Infinity, 1); // -Infinity (正の奇数の整数の指数)Math.pow(-Infinity, 1.5); // Infinity (正の指数)Math.pow(-Infinity, -1); // -0 (負の奇数の整数の指数)Math.pow(-Infinity, -1.5); // 0 (負の指数)Math.pow(0, 1); // 0 (正の指数)Math.pow(0, -1); // Infinity (負の指数)Math.pow(-0, 1); // -0 (正の奇数の整数の指数)Math.pow(-0, 1.5); // 0 (正の指数)Math.pow(-0, -1); // -Infinity (負の奇数の整数の指数)Math.pow(-0, -1.5); // Infinity (負の指数)Math.pow(0.9, Infinity); // 0Math.pow(1, Infinity); // NaNMath.pow(1.1, Infinity); // InfinityMath.pow(0.9, -Infinity); // InfinityMath.pow(1, -Infinity); // NaNMath.pow(1.1, -Infinity); // 0// NaN: only Math.pow(NaN, 0) does not result in NaNMath.pow(NaN, 0); // 1Math.pow(NaN, 1); // NaNMath.pow(1, NaN); // NaN仕様書
| Specification |
|---|
| ECMAScript® 2026 Language Specification> # sec-math.pow> |