--- title: 按位与赋值(&=) slug: Web/JavaScript/Reference/Operators/Bitwise_AND_assignment tags: - JavaScript - 按位与赋值运算 - 操作符运算 translation_of: Web/JavaScript/Reference/Operators/Bitwise_AND_assignment ---
{{jsSidebar("Operators")}}
按位与赋值运算符(&=)表示两个操作数的二进制,对它们进行按位AND运算并将结果分配给变量。
{{EmbedInteractiveExample("pages/js/expressions-bitwise-and-assignment.html")}}

语法

Operator: x &= y
Meaning:  x  = x & y

例子

按位与赋值运算

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

规范

Specification
{{SpecName('ESDraft', '#sec-assignment-operators', 'Assignment operators')}}

浏览器兼容性

{{Compat("javascript.operators.bitwise_and_assignment")}}

参见