Skip to content

Instantly share code, notes, and snippets.

@skellertor
Created April 26, 2017 15:42
Show Gist options
  • Save skellertor/55cc36a65b79c879abfd864d3885957e to your computer and use it in GitHub Desktop.
Save skellertor/55cc36a65b79c879abfd864d3885957e to your computer and use it in GitHub Desktop.
Javascript truthy/falsey
// Outputs: "Truthy!"
logTruthiness(true);
// Outputs: "Truthy!"
logTruthiness({});
// Outputs: "Truthy!"
logTruthiness([]);
// Outputs: "Truthy!"
logTruthiness("some string");
// Outputs: "Truthy!"
logTruthiness(3.14);
// Outputs: "Truthy!"
logTruthiness(new Date());
// Outputs: "Falsy."
logTruthiness(false);
// Outputs: "Falsy."
logTruthiness(null);
// Outputs: "Falsy."
logTruthiness(undefined);
// Outputs: "Falsy."
logTruthiness(NaN);
// Outputs: "Falsy."
logTruthiness(0);
// Outputs: "Falsy."
logTruthiness("");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment