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 –
- a = First operand
- b = Second operand
Example 1: In this example, we will see the bitwise AND Assignment.
Javascript
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.
Javascript
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:
- Chrome 1
- Edge 12
- Firefox 1
- Opera 3
- Safari 1