In this article, you’ll learn how to convert a boolean to a string in javascript. There are two ways to convert a boolean value to a string value in JavaScript.
Here is the example to convert a boolean to a string in Javascript.
In this example, we used the toString()
method to convert a boolean (true
or false
) to its respective string.
console.log(true.toString());
// output ==> "true"
console.log(false.toString());
// output ==> "false"
In this example, you can concatenate a boolean value and an empty string (''
) to convert it to a string.
console.log(''+true);
// output ==> "true"
console.log(typeof (''+false) === 'string');
// it checks if the value is string or not
// output ==> true
I hope this article will help you to understand how to convert a boolean to a string in javascript.
Share your valuable feedback, please post your comment at the bottom of this article. Thank you!
Comments