--- title: Bitwise OR assignment (|=) slug: Web/JavaScript/Reference/Operators/Bitwise_OR_assignment translation_of: Web/JavaScript/Reference/Operators/Bitwise_OR_assignment ---
{{jsSidebar("Operators")}}

The bitwise OR assignment operator (|=) uses the binary representation of both operands, does a bitwise OR operation on them and assigns the result to the variable.

{{EmbedInteractiveExample("pages/js/expressions-bitwise-or-assignment.html")}}

语法

Operator: x |= y
Meaning:  x  = x | y

Examples

Using bitwise OR assignment

let a = 5;
a |= 2; // 7
// 5: 00000000000000000000000000000101
// 2: 00000000000000000000000000000010
// -----------------------------------
// 7: 00000000000000000000000000000111

Specifications

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

Browser compatibility

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

See also