What is the role of the bitwise AND (&) operator in JavaScript?

In JavaScript, the bitwise AND (`&`) operator is used to perform a bitwise AND operation on the individual bits of two integers. It compares each bit of the first operand to the corresponding bit of the second operand and returns a new integer with bits set to 1 only where both operands have corresponding bits set to 1.

Here's a basic example of bitwise AND in action:


let num1 = 5;  // Binary: 0101
let num2 = 3;  // Binary: 0011

let result = num1 & num2;  // Bitwise AND

console.log(result);  // Outputs: 1 (Binary: 0001)


Explanation:
- `num1` in binary is `0101`.
- `num2` in binary is `0011`.
- The bitwise AND operation compares each pair of corresponding bits. If both bits are `1`, the result has a `1` in that position; otherwise, it has a `0`.
- In this example, the result is `0001` in binary, which is `1` in decimal.

The bitwise AND operator is often used in scenarios where specific bits in an integer need to be checked or modified. For example, it can be used in conjunction with bit masks for certain low-level operations or to perform specific bitwise manipulations.

Keep in mind that when working with bitwise operations, the values involved are treated as 32-bit signed integers in two's complement form in JavaScript. If you perform bitwise operations on non-integer values, JavaScript converts them to integers before the operation.