Bitwise OR then assign (|=) (Operator/assignment)

Bitwise OR two operands and assign the result to the first.

Availability:

ECMAScript edition - 2
JavaScript - 1.0
JScript - 1.0
Internet Explorer - 3.02
Netscape - 2.0
Netscape Enterprise Server - 2.0
Opera - 3.0
Property/method value type:Number primitive
JavaScript syntax:-anOperand1 |= anOperand2
Argument list:anOperand1A numeric value that can be assigned to
anOperand2Another numeric value

Bitwise OR the right operand with the left operand and assign the result to the left operand.

This is functionally equivalent to the expression:

anOperand1 = anOperand1 | anOperand2;

Performs a bit-by-bit OR of the 32-bit value derived from both operands.

Where a corresponding bit is 1 in either of the two operands, a 1 is inserted into the result. A zero is inserted only when neither operand has a 1 bit at that position.

Although this is classified as an assignment operator it is really a compound of an assignment and a bitwise operator.

The associativity is right to left.

Refer to the Operator Precedence topic for details of execution order.

The new value of anOperand1 is returned as a result of the expression.

The truth table shows the result of this operator for two Boolean primitive values:

ABOR
falsefalsefalse
falsetruetrue
truefalsetrue
truetruetrue

This is applied to each corresponding bit pair in the operands.

Warnings:

See also:Assignment operator, Associativity, Bit-field, Bitwise operator, Bitwise OR (|), LValue, Operator Precedence

Cross-references:

ECMA 262 edition 2 - section - 11.13

ECMA 262 edition 3 - section - 11.13