What does ~~ (“double tilde”) do in Javascript?

前端 未结 9 758
有刺的猬
有刺的猬 2020-11-22 17:16

I was checking out an online game physics library today and came across the ~~ operator. I know a single ~ is a bitwise NOT, would that make ~~ a NOT of a NOT, which would

9条回答
  •  天涯浪人
    2020-11-22 18:00

    The ~ seems to do -(N+1). So ~2 == -(2 + 1) == -3 If you do it again on -3 it turns it back: ~-3 == -(-3 + 1) == 2 It probably just converts a string to a number in a round-about way.

    See this thread: http://www.sitepoint.com/forums/showthread.php?t=663275

    Also, more detailed info is available here: http://dreaminginjavascript.wordpress.com/2008/07/04/28/

提交回复
热议问题