Created
September 12, 2015 00:32
-
-
Save mnkhouri/b5beb5d9b34ad09339c9 to your computer and use it in GitHub Desktop.
Node coercion to bool
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
#!/usr/bin/env node | |
var testZero = 0 | |
if (testZero) { | |
console.log("int 0 evaluated TRUE") | |
} | |
else { | |
console.log("int 0 evaluated FALSE") | |
} | |
testZero = "0" | |
if (testZero) { | |
console.log("string 0 evaluated TRUE") | |
} | |
else { | |
console.log("string 0 evaluated FALSE") | |
} | |
/********* | |
OUTPUT | |
********** | |
⇒ ./test | |
int 0 evaluated FALSE | |
string 0 evaluated TRUE | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment