Last active
May 25, 2016 16:00
-
-
Save stevenpollack/e5964e13ed52af0ef120209b02699386 to your computer and use it in GitHub Desktop.
Javascript "falsey" values
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
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