<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
How to define Global Variable in JavaScript?
How to join string with number in JavaScript?
How to change text color on click using JavaScript?
JavaScript example to change image on click
Highlight and get the details of table row on click using JavaScript
JavaScript check if first string contains all characters of second string