Discussion: Casting Spells with 1s and 0s
Execute the code to understand the output and gain insights into how to use the tilde operator to convert a floating-point number into an integer in JavaScript.
We'll cover the following...
Verifying the output
Now, it’s time to execute the code and observe the output.
Press + to interact
const x = ~~(7.9);console.log(x);
Bitwise NOT operator
The tilde (~
) symbol in JavaScript is known as the bitwise NOT operator. It takes the binary representation of a number and flips all the bits, resulting in a new number. Now, the thing is, bitwise operators in JavaScript work with integers, not floating-point numbers.