In this article, you’ll learn how to convert a string to a boolean in javascript. To convert the string value ('true'
or 'false'
) to a boolean you can do this as given below example:
const value = 'true';
console.log(value == 'true');
// output ==> "true"
And to handle case sensitive strings you can do this as given below:
const value = 'False';
console.log(value.toLowerCase() === 'false');
// output ==> "true"
I hope this article will help you to understand how to convert a string to a boolean in javascript.
Share your valuable feedback, please post your comment at the bottom of this article. Thank you!
Comments