Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

我的学习日志(九) #11

Open
xxxgitone opened this issue Jul 1, 2017 · 0 comments
Open

我的学习日志(九) #11

xxxgitone opened this issue Jul 1, 2017 · 0 comments

Comments

@xxxgitone
Copy link
Owner

好玩的(字位操作"非")运算符,之前在《你不知道的JavaScript 中卷》看到过这个运算符的介绍,不过自己在写代码的过程中几乎没有用到过,就没有很在意它。最近经常看到别人在自己的项目中用到这个运算符,于是又特意再来感受这个运算符的神奇

用的比较多的就是使用~~来取整

~~ 53.6  //53
Math.floor(53.6) // 53

上面效果和Math.floor()一样,但是在处理负数的时候就会有区别

~~ -53.6  // -53
Math.floor(-53.6) //  -54

使用运算符确实简洁不少,在使用第一个~的时候执行ToInt32并反转字位,然后第二个~再进行一次字位反转,即将所有的字位反转回原值,最后得到的仍然是ToInt32的结果

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant