Skip to content

Instantly share code, notes, and snippets.

@stevenpollack
Last active May 25, 2016 16:00
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 stevenpollack/e5964e13ed52af0ef120209b02699386 to your computer and use it in GitHub Desktop.
Save stevenpollack/e5964e13ed52af0ef120209b02699386 to your computer and use it in GitHub Desktop.
Javascript "falsey" values
var falseyValues = [
false,
0,
undefined,
NaN,
"",
null
];
falseyValues.map(function (x) {return x ? true : false;}); // [false, false, false, false, false, false]
/*
* in &&-assignment JS will take the right-most truthy value, if the circuit isn't broken,
* or the left-most (first) falsey value if it is:
*/
true && 1 // yields 1
true && 0 == true && 0 && 1 // yields 0
// ^ broken at value 0 -- everything else is ignored ^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment