Bitwise AND Operator (&) (JavaScript)

Performs a bitwise AND operation on two 32-bit expressions.

Syntax


result = expression1 & expression2  

Parameters

result
The result of the operation.

expression1
Any expression.

expression2
Any expression.

Remarks

The & does a bitwise AND operation on the each of the bits of two 32-bit expressions. If both of the bits are 1, the result is 1. Otherwise, the result is 0.

Bit1 Bit2 ANDed Value
0 0 0
1 1 1
1 0 0
0 1 0

The following examples show how to use the & operator.

// 9 is 00000000000000000000000000001001  
var expr1 = 9;  

// 5 is 00000000000000000000000000000101  
var expr2 = 5;  

// 1 is 00000000000000000000000000000001  
var result = expr1 & expr2;  

document.write(result);  
// Output: 1  

Requirements

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, Internet Explorer 11 standards. Also supported in Store apps (Windows 8 and Windows Phone 8.1). See Version Information.

See Also

Bitwise AND Assignment Operator (&=)
Operator Precedence
Operator Summary (JavaScript)