Search⌘ K
AI Features

Discussion: Casting Spells with 1s and 0s

Explore how the double tilde bitwise NOT operator works in JavaScript to truncate decimal numbers and convert them to integers. Understand the binary flipping process, why it produces certain results, and when to prefer standard functions like Math.floor for safe conversions beyond 32-bit integer ranges.

Verifying the output

Now, it’s time to execute the code and observe the output.

Javascript (babel-node-es2024)
const x = ~~(7.9);
console.log(x);

Bitwise NOT operator

...