-
-
Save chrisLeeTW/a05402052acd9a0c8dd19358a8c282e6 to your computer and use it in GitHub Desktop.
JavaScript: String to Boolean
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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