What is the Double Tilde Operator in JavaScript



The “double tilde” (~~) operator is a double NOT Bitwise operator. Use it as a substitute for Math.floor(), since it’s faster.

Example

You can try to run the following code to learn about double tilde operator −

<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>
Updated on: 2020-06-13T09:22:07+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements