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');