What is ~~ in javascript?

Possible duplicate:
Understanding in different ways javascript NOT

I found it here: the question is before the interview questions below. What will this code ~~ 3.14 return?

I searched on google but found nothing on this.

+5
source share
3 answers

It will return 3. ~represents the bitwise NOT operator in JavaScript.

Basically, ~ 3.14 matches ~ 3, which is ~ 011 in binary => 100 or 4 in base 10. ~ 4 or ~ 100 is 011 or 3 in base 10.

+5
source

~ - JavaScript ( C/++ ). : (~)?

:

, ~n -n-1 Two Complement.

+5

32- .

MDN:

x -(x + 1). , ~5 -6.

In your case:

  ~~3.14
= -((~3.14) + 1)
= -(-(3.14 + 1) + 1)
= -(-(3 + 1) + 1)
= -(-4 + 1)
= -(-3)
= 3
+4
source

All Articles