Created
December 2, 2009 17:36
-
-
Save karbassi/247375 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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