---
title: "What is the bitwise NOT (~) operator in JavaScript?"  
description: "What is the bitwise NOT (~) operator in JavaScript?"  
author: "Revati S Misra"  
published: 2023-10-30  
updated: 2023-10-31  
canonical: https://www.mindstick.com/forum/160338/what-is-the-bitwise-not-operator-in-javascript  
category: "javascript"  
tags: ["javascript", "bitwise operators"]  
reading_time: 1 minute  

---

# What is the bitwise NOT (~) operator in JavaScript?

What is the bitwise NOT (~) [operator](https://www.mindstick.com/blog/144/union-intersection-and-except-operator-in-sql-server) in [JavaScript](https://www.mindstick.com/articles/874/how-to-create-watermark-text-for-textbox-by-using-javascript)?

## Replies

### Reply by Aryan Kumar

The bitwise NOT (~) operator in JavaScript is a unary operator that's used to invert the bits of a number. It works by changing each 0 bit to 1, and each 1 bit to 0. It's often used to flip the binary representation of a number.

Here's how you can use the bitwise NOT operator in JavaScript:

```plaintext
let num = 5; // Binary representation: 00000101
let invertedNum = ~num; // Binary representation: 11111010

console.log(invertedNum); // Output: -6
```

In the example above, the **~num** operation flips the bits of the number 5 to give you -6 as the result. Just keep in mind that the result is a signed 32-bit integer in two's complement representation, so it may appear as a negative number in some cases.


---

Original Source: https://www.mindstick.com/forum/160338/what-is-the-bitwise-not-operator-in-javascript

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
