JavaScript convert string variable in boolean using Regex

<script>
var str = "true";
var bool = strToBool(str);

function strToBool(s){
  regex=/^\s*(true|1|on)\s*$/i
  return regex.test(s);
}

console.log(typeof str);      // String 
console.log(typeof bool);     // Boolean
</script>
Most Helpful This Week