Horje
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 –

  • 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


Reffered: https://www.geeksforgeeks.org


JavaScript

Related
JavaScript return Statement JavaScript return Statement
JavaScript Set keys() Method JavaScript Set keys() Method
JavaScript Array() Constructor JavaScript Array() Constructor
Bitwise XOR Assignment (^=) Operator in JavaScript Bitwise XOR Assignment (^=) Operator in JavaScript
Bitwise OR Assignment (|=) Operator in JavaScript Bitwise OR Assignment (|=) Operator in JavaScript

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
12