1var myBool = Boolean("false"); // == true
2
3var myBool = !!"false"; // == true
1let toBool = string => string === 'true' ? true : false;
2// Not everyone gets ES6 so here for the beginners
3function toBool(string){
4 if(string === 'true'){
5 return true;
6 } else {
7 return false;
8 }
9}
1stringToBoolean: function(string){
2 switch(string.toLowerCase().trim()){
3 case "true": case "yes": case "1": return true;
4 case "false": case "no": case "0": case null: return false;
5 default: return Boolean(string);
6 }
7}
1// Do
2var isTrueSet = (myValue == 'true');
3// Or
4var isTrueSet = (myValue === 'true');
1// Everyone does one extra check. Here is a better answer
2
3let toBool = string => string === 'true'; // ? true : false;
4// Not everyone gets ES6 so here for the beginners
5function toBool(string){
6 return string === 'true';
7}