---
title: "Explain the bitwise AND (&) operator in JavaScript."  
description: "Explain the bitwise AND (&) operator in JavaScript."  
author: "Revati S Misra"  
published: 2023-10-30  
updated: 2023-10-31  
canonical: https://www.mindstick.com/forum/160334/explain-the-bitwise-and-operator-in-javascript  
category: "javascript"  
tags: ["javascript", "bitwise operators"]  
reading_time: 2 minutes  

---

# Explain the bitwise AND (&) operator in JavaScript.

[Explain the bitwise](https://www.mindstick.com/forum/160336/explain-the-bitwise-or-operator-in-javascript) AND (&) [operator](https://www.mindstick.com/blog/144/union-intersection-and-except-operator-in-sql-server) in JavaScript.

## Replies

### Reply by Aryan Kumar

The bitwise AND (&) operator in JavaScript is used to perform a bitwise AND operation on the individual bits of two numbers. It returns a new number where each bit is set to 1 only if the corresponding bits in both input numbers are 1.

Here's a simple explanation of how the bitwise AND operator works:

1. For each pair of bits in the same position in the binary representations of the two numbers:

- If both bits are 1, the result bit at that position is set to 1.
- Otherwise, if at least one of the bits is 0, the result bit at that position is set to 0.

Here's an example:

```plaintext
let num1 = 5;  // Binary representation: 00000101
let num2 = 3;  // Binary representation: 00000011

let result = num1 & num2;  // Binary representation: 00000001

console.log(result);  // Output: 1
```

In this example, the bitwise AND operation is applied to **num1** and **num2**. The result has a 1 at the 2^0 position because it's the only position where both input numbers have a 1.

The bitwise AND operator is commonly used for tasks like isolating or testing specific bits within a number, setting certain bits to 0 in a binary representation, or performing bitwise operations in various programming scenarios.


---

Original Source: https://www.mindstick.com/forum/160334/explain-the-bitwise-and-operator-in-javascript

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
