Content-Length: 257457 | pFad | http://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Operators/Exponentiation_assignment

べき乗代入演算子 (**=) - JavaScript | MDN

このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

べき乗代入演算子 (**=)

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2017年3月.

べき乗代入演算子 (**=) は、べき乗を 2 つのオペランドで実行し、結果を左オペランドに代入します。

試してみましょう

let a = 3;

console.log((a **= 2));
// 予想される結果: 9

console.log((a **= 0));
// 予想される結果: 1

console.log((a **= "hello"));
// 予想される結果: NaN

構文

js
x **= y

解説

x **= yx = x ** y と同等ですが、式 x が一度だけ評価される点が異なります。

べき乗代入の仕様

js
let bar = 5;
bar **= 2; // 25

その他の長整数でない値は、数値に変換されます。

js
let baz = 5;
baz **= "foo"; // NaN

長整数を使用したべき乗代入

js
let foo = 3n;
foo **= 2n; // 9n
foo **= 1; // TypeError: Cannot mix BigInt and other types, use explicit conversions

仕様書

Specification
ECMAScript® 2026 Language Specification
# sec-assignment-operators

ブラウザーの互換性

関連情報









ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Operators/Exponentiation_assignment

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy