--- title: Bitwise OR assignment (|=) slug: Web/JavaScript/Reference/Operators/Bitwise_OR_assignment translation_of: Web/JavaScript/Reference/Operators/Bitwise_OR_assignment --- <div>{{jsSidebar("Operators")}}</div> <p>The bitwise OR assignment operator (<code>|=</code>) uses the binary representation of both operands, does a bitwise OR operation on them and assigns the result to the variable.</p> <div>{{EmbedInteractiveExample("pages/js/expressions-bitwise-or-assignment.html")}}</div> <h2 id="语法">语法</h2> <pre class="syntaxbox"><strong>Operator:</strong> x |= y <strong>Meaning:</strong> x = x | y</pre> <h2 id="Examples">Examples</h2> <h3 id="Using_bitwise_OR_assignment">Using bitwise OR assignment</h3> <pre class="brush: js">let a = 5; a |= 2; // 7 // 5: 00000000000000000000000000000101 // 2: 00000000000000000000000000000010 // ----------------------------------- // 7: 00000000000000000000000000000111</pre> <h2 id="Specifications">Specifications</h2> <table class="standard-table"> <thead> <tr> <th scope="col">Specification</th> </tr> </thead> <tbody> <tr> <td>{{SpecName('ESDraft', '#sec-assignment-operators', 'Assignment operators')}}</td> </tr> </tbody> </table> <h2 id="Browser_compatibility">Browser compatibility</h2> <p>{{Compat("javascript.operators.bitwise_or_assignment")}}</p> <h2 id="See_also">See also</h2> <ul> <li><a href="/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Assignment">Assignment operators in the JS guide</a></li> <li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_OR">Bitwise OR operator</a></li> <li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Logical_OR_assignment">Logical OR assignment (<code>||=</code>)</a></li> </ul>