Favorites

JavaScript ~ Bitwise NOT Operator

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
~
JavaScript Bitwise OperatorThis operator is supported by all modern browsers.
Updated 28th November 2026

The bitwise NOT operator (~) inverts every bit of a 32-bit integer, which turns n into -(n + 1).

Description

The bitwise NOT operator ~ flips every bit of its operand's 32-bit integer form, which for whole numbers gives -(n + 1). Older code used ~str.indexOf(x) as a "found" check because ~-1 is 0; includes() is the clearer modern choice.

Applying it twice, ~~x, truncates a number towards zero, which was once a popular shortcut for Math.trunc(). It only works correctly for values within the 32-bit integer range, so for large numbers it gives wrong results; Math.trunc() is safer and clearer.

With bit flags, ~FLAG inverts a mask so it can be combined with & to clear that flag: flags &= ~FLAG. With a BigInt, ~ returns a BigInt.

Properties

Operator
~
Category
Bitwise
Precedence
14 (1 is lowest, 18 is highest)
Associativity
right-to-left

Syntax

~x

Example

console.log(~5, ~-1, ~0);
console.log(!!~'hello'.indexOf('ell'));

Browser Support

The following information will show you the current browser support for the ~ operator. Hover over a browser icon to see the version that first introduced support for this operator.

This operator is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee