このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docsコミュニティーについてもっと知り、仲間になるにはこちらから。
ビット論理積代入演算子 (&=)
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月.
ビット論理積代入 (&=) 演算子は、 2 つのオペランドで論理積を取り、その結果を左オペランドへ代入します。
In this article
試してみましょう
let a = 5; // 00000000000000000000000000000101a &= 3; // 00000000000000000000000000000011console.log(a); // 00000000000000000000000000000001// 予想される結果: 1構文
js
x &= y解説
x &= y はx = x & y と同等ですが、x は一度しか評価されません。
例
>ビット論理積代入の使用
js
let a = 5;// 5: 00000000000000000000000000000101// 2: 00000000000000000000000000000010a &= 2; // 0let b = 5n;b &= 2n; // 0n仕様書
| Specification |
|---|
| ECMAScript® 2026 Language Specification> # sec-assignment-operators> |