Open In App

Bitwise AND Assignment (&=) Operator in JavaScript

The Bitwise AND Assignment Operator is represented by “&=”. This operator uses the binary representation of both operands and performs the bitwise AND operation and then assigns the result to the left operand. 

This can also be explained as applying the logical AND operation to the first operand and second operand and after that assigning the result to the first operand.



Syntax:

a &= b 
Or
a = a & b

 



Where –

Example 1: In this example, we will see the bitwise AND Assignment.




let x = 7;      // 00000000000000000000000000000111
x &= 3;         // 00000000000000000000000000000011
  
console.log(x);

Output:

3

Example 2: In this example, we will see the logical AND operation between two operands.




let x = 7;
let y = 3;
x &= y;
console.log(x); 
  
x &= 0;
console.log(x);

Output:

3
0

We have a complete list of Javascript Assignment Operators, to go through those please check the Javascript Assignment Operator article.

Supported Browser:

Article Tags :