← 返回首页
ビット論理積代入演算子 (&=) - 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 2015年7月.

ビット論理積代入 (&=) 演算子は、 2 つのオペランドで論理積を取り、その結果を左オペランドへ代入します。

In this article

試してみましょう

let a = 5; // 00000000000000000000000000000101 a &= 3; // 00000000000000000000000000000011 console.log(a); // 00000000000000000000000000000001 // 予想される結果: 1

構文

js
x &= y

解説

x &= y は x = x & y と同等ですが、 x は一度しか評価されません。

ビット論理積代入の使用

js
let a = 5; // 5: 00000000000000000000000000000101 // 2: 00000000000000000000000000000010 a &= 2; // 0 let b = 5n; b &= 2n; // 0n

仕様書

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

ブラウザーの互換性

Enable JavaScript to view this browser compatibility table.

関連情報