Skip to content

Instantly share code, notes, and snippets.

@flipjs
Created August 3, 2014 20:53
Show Gist options
  • Save flipjs/815603026e4a3801eef1 to your computer and use it in GitHub Desktop.
Save flipjs/815603026e4a3801eef1 to your computer and use it in GitHub Desktop.
Truthey Tester by Angus Croll
var trutheyTester = function(expr) {
return expr ? "truthey" : "falsey";
}
trutheyTester({}); //truthey (an object is always true)
trutheyTester(false); //falsey
trutheyTester(new Boolean(false)); //truthey (an object!)
trutheyTester(""); //falsey
trutheyTester(new String("")); //truthey (an object!)
trutheyTester(NaN); //falsey
trutheyTester(new Number(NaN)); //truthey (an object!)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment