Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save chrisLeeTW/a05402052acd9a0c8dd19358a8c282e6 to your computer and use it in GitHub Desktop.
Save chrisLeeTW/a05402052acd9a0c8dd19358a8c282e6 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