Skip to content

Instantly share code, notes, and snippets.

@gsans
Last active March 10, 2016 11:23
Show Gist options
  • Save gsans/93a6a9edbdf2a393bbb4 to your computer and use it in GitHub Desktop.
Save gsans/93a6a9edbdf2a393bbb4 to your computer and use it in GitHub Desktop.
(function () {
'use strict';
var u; //undefined
// all pass this test
console.log(!""==true); // true
console.log(!0==true); // true
console.log(!null==true); // true
console.log(!NaN==true); // true
console.log(!false==true); // true
console.log(!u==true); // true
// but falsy is not always false
console.log("-");
console.log(""==false); // true
console.log(0==false); // true
console.log(null==false); // false WAT?!
console.log(NaN==false); // false WAT?!
console.log(false==false); // true
console.log(u==false); // false WAT?!
//take home
// 1) Use negation with falsy values. Don't use == or !=
// if (!falsy) // good
// if (falsy==false || falsy!=true) // won't work as expected
// Weird cases
console.log("-");
console.log([]==false); // true
if(![]) console.log("falsy"); // but not falsy =/
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment