Skip to content

Instantly share code, notes, and snippets.

@mnkhouri
Created September 12, 2015 00:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mnkhouri/b5beb5d9b34ad09339c9 to your computer and use it in GitHub Desktop.
Save mnkhouri/b5beb5d9b34ad09339c9 to your computer and use it in GitHub Desktop.
Node coercion to bool
#!/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