Last active
July 27, 2020 03:11
-
-
Save davidlonjon/5882129 to your computer and use it in GitHub Desktop.
JavaScript: String to Boolean
This file contains 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