Last updated on Sep 27, 2020 by Suraj Sharma
In this tutorial, you will learn to convert a string to a boolean in JavaScript
Consider, a user has entered a 'true'
or a 'false'
value in the input field in the form.
To convert the 'true'
or 'false'
string value to a boolean we can do like this
const value = 'true';
const booleanValue = value === 'true'; // true
To handle case-sensitive strings.
const value = 'False';
const booleanValue = value.toLowerCase() === 'true'; // false
Related Solutions
Rate this post
Suraj Sharma is the founder of Future Gen AI Services. He holds a B.Tech degree in Computer Science & Engineering from NIT Rourkela.