Expand Minimize
This topic has not yet been rated - Rate this topic

Bitwise AND Assignment Operator (&=) (JavaScript)

JavaScript - Internet Explorer 10

Sets the result of a bitwise AND operation on the value of a variable and the value of an expression. The variable and the expression are treated as 32-bit integers.

result &= expression
result

Any variable.

expression

Any expression.

Using this operator is the same as specifying:

result = result & expression

The Bitwise AND Operator (&) (JavaScript) looks at the binary representation of the values of result and expression and does a bitwise AND operation on them. The output of this operation behaves like this:

// 9 is 00000000000000000000000000001001
var expr1 = 9;

// 5 is 00000000000000000000000000000101
var expr2 = 5;
 

// 1 is 00000000000000000000000000000001
expr1 &= expr2;

document.write(expr1);

Any time both of the expressions have a 1 in a digit, the result has a 1 in that digit. Otherwise, the result has a 0 in that digit.

Supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards. Also supported in Windows Store apps. See Version Information.

Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.