Possible Duplicate:
Understanding javascript bitwise NOT
I found it here: front-end-interview-questions question down below. what this code ~~3.14 will return?
I searched on google but didn't found anything on this.
~
is the bitwise complement operator in JavaScript (and C/C++ and other languages).
You can find more details here: How does the bitwise complement (~) operator work?
In this case:
3.14
is converted from floating point to integer, so it becomes 3
.~3
is -4
because of the Two's Complement representation.~(-4)
becomes 3
.Basically, ~n
is equal to -n-1
for integers with Two's Complement representation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With