什么是JavaScript中的“双波浪号”(~~)运算符?

阅读 133 收藏 0 点赞 0 评论 0

“ double tilde”(~~)运算符是double NOT按位运算符。用它代替Math.floor(),因为它更快。

示例

您可以尝试运行以下代码以了解双波浪号运算符-

<html>
   <body>
      <script>
         var a = 2;
         var b,c, d;

         b = ~~a;
         c = Math.floor(a);
         d = ~~b=== c;

         document.write(b);
         document.write("<br>"+c);
         document.write("<br>"+d); // They are equal
      </script>
   </body>
</html>
评论列表


问题


面经


文章

微信
公众号

扫码关注公众号