Skip to content

Instantly share code, notes, and snippets.

@furf
Created February 16, 2010 14:27
Show Gist options
  • Save furf/305553 to your computer and use it in GitHub Desktop.
Save furf/305553 to your computer and use it in GitHub Desktop.
// Empty strings are truthy-falsy...
var EMPTY = "";
EMPTY == true; // false
EMPTY == false; // true
// ...but non-empty strings are NOT.
var NON_EMPTY = "hello, world";
NON_EMPTY == true; // false
NON_EMPTY == false; // false
// Neither are "true" nor "false"...
var FALSE = "false";
FALSE == true; // false
FALSE == false; // false
var TRUE = "true";
TRUE == true; // false
TRUE == false; // false
// ...nor "undefined" nor "null".
var UNDEFINED = "undefined";
UNDEFINED == true; // false
UNDEFINED == false; // false
var NULL = "null";
NULL == true; // false
NULL == false; // false
// But numeric strings are truthy-falsy...
var ZERO = "0";
ZERO == true; // false
ZERO == false; // true
var ONE = "1";
ONE == true; // true
ONE == false; // false
// ...as long as they are only "0" or "1".
var TWO = "2";
TWO == true; // false
TWO == false; // false
var NEGATIVE_ONE = "-1";
NEGATIVE_ONE == true; // false
NEGATIVE_ONE == false; // false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment