Guest User

Untitled

a guest
Apr 21st, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. // If you want to flip a variable from true to false, you can do the following:
  2.  
  3. var x = false;
  4. x = !!(~x+2);
  5.  
  6. // At this point, x is true.
  7.  
  8. // You can also do this with numbers.
  9. // Let's say you want to flip 0 to 1 or 1 to 0.
  10.  
  11. var y = 1;
  12. y = ~y+2;
  13.  
  14. // At this point, y is 0.
  15.  
  16. // As you can see, the number bitwise NOT operation is used in flipping boolean values.
Add Comment
Please, Sign In to add comment