2

Possible Duplicate:
What is the “double tilde” (~~) operator in JavaScript?

I was wondering for a time now what exactly the ~~ operator does in javascript.

It seems it does essentially the same as Math.floor at least when looking at the result.

~~(1.2345) //1
Math.floor(1.2345) // 1

The other thing is that i don't find anything about it anywhere. Well, google doesn't let one search for "~~"

But also when looking at the ECMA Script Specification i can't seem to find a single entry mentioning ~~

And running a benchmark on both gives a surprising result too. As Math.floor is

  • Chrome - 1%
  • Firefox - 54%
  • Internet Explorer - 84%

slower for me than ~~.

Could anyone please shine a light on this?
Thanks in advance =)

Community
  • 1
  • 1
Moritz Roessler
  • 8,542
  • 26
  • 51

0 Answers0