Articles → JAVASCRIPT → Convert String To Boolean Value In Javascript

Convert String To Boolean Value In Javascript






Code




<script>
    var stringValue = "TRUE";

    var bool_value = stringValue.toLowerCase() === 'true';
    // Returns true
    console.log(bool_value);


    stringValue = "False";
    bool_value = stringValue.toLowerCase() === 'true';
    // Returns false
    console.log(bool_value);

</script>



Output


Picture showing the output of converting string to boolean in javascript



Posted By  -  Karan Gupta
 
Posted On  -  Wednesday, February 9, 2022

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250