I was just messing with random stuff, while I found something interesting..
if I have ~ before a number, for example I have tried
~110100100 // result will be " -110100101 "
~11 // result will be " -12 "
is it making it negative and reducing it by 1? I don't have any idea, can anyone pleas explain this??
The Complete Full-Stack JavaScript Course! The “double tilde” (~~) operator is a double NOT Bitwise operator. Use it as a substitute for Math. floor(), since it's faster.
The main difference between the == and === operator in javascript is that the == operator does the type conversion of the operands before comparison, whereas the === operator compares the values as well as the data types of the operands.
That ~~ is a double NOT bitwise operator. It is used as a faster substitute for Math. floor() for positive numbers.
The operator ~
returns that result:
~N = -(N+1)
But this is an effect of inverting the value of all bits of a variable.
Double tilde ~~
is used to convert some types to int, since ~
operator converts the value to a 32-bit int before inverting its bits. Thus:
~~'-1' = -1
~~true = 1
~~false = 0
~~5.6 = 5
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