javascript bitwise operator question

前端 未结 4 553
渐次进展
渐次进展 2020-12-20 00:24

In Javascript when I do this

var num = 1;

~ num == -2

why does ~num not equal 0

in binary 1 is st

4条回答
  •  有刺的猬
    2020-12-20 01:19

    From the documentation:

    Bitwise NOTing any number x yields -(x + 1). For example, ~5 yields -6.

提交回复
热议问题