Skip to content

Instantly share code, notes, and snippets.

@simonpioli
Created June 26, 2013 11:12
Show Gist options
  • Save simonpioli/5866633 to your computer and use it in GitHub Desktop.
Save simonpioli/5866633 to your computer and use it in GitHub Desktop.
Converts a string to boolean in Javascript. Useful if passing settings through data- attributes.
function stringToBoolean(string){
switch(string.toLowerCase()){
case "true": case "yes": case "1": return true;
case "false": case "no": case "0": case "": return false;
default: return Boolean(string);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment