Skip to content

Instantly share code, notes, and snippets.

@davidlonjon
Last active July 27, 2020 03:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save davidlonjon/5882129 to your computer and use it in GitHub Desktop.
Save davidlonjon/5882129 to your computer and use it in GitHub Desktop.
JavaScript: String to Boolean
// Taken from:
// http://stackoverflow.com/questions/263965/how-can-i-convert-a-string-to-boolean-in-javascript
stringToBoolean = function(string) {
switch(string.toLowerCase()){
case "true": case "yes": case "1": return true;
case "false": case "no": case "0": case null: return false;
default: return Boolean(string);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment