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

前端 未结 9 514
有刺的猬
有刺的猬 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 17:45

    Here is an example of how this operator can be used efficiently, where it makes sense to use it:

    leftOffset = -(~~$('html').css('padding-left').replace('px', '') + ~~$('body').css('margin-left').replace('px', '')),
    

    Source:

    See section Interacting with points

提交回复
热议问题