Skip to content

Instantly share code, notes, and snippets.

@karbassi
Created December 2, 2009 17:36
Show Gist options
  • Save karbassi/247375 to your computer and use it in GitHub Desktop.
Save karbassi/247375 to your computer and use it in GitHub Desktop.
// If you want to flip a variable from true to false, you can do the following:
var x = false;
x = !!(x-1);
// At this point, x is true.
// Let's say you want to flip 0 to 1 or 1 to 0:
var y = 1;
y = -y+1;
// At this point, y is 0.
// Also to convert boolean to int real fast.
var y = false;
y = +y;
// y = 0
// Reference: http://www.jibbering.com/faq/faq_notes/type_convert.html#tcNumber
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment