Sometimes, we want to convert truthy or falsy to an explicit boolean with JavaScript.
In this article, we’ll look at how to convert truthy or falsy to an explicit boolean with JavaScript.
How to convert truthy or falsy to an explicit boolean with JavaScript?
To convert truthy or falsy to an explicit boolean with JavaScript, we use the Boolean function.
For instance, we write
const tata = Boolean(toto);
to convert the toto value to a boolean by calling Boolean to return the boolean value of toto.
If toto is truthy, Boolean returns true.
Otherwise, it returns false.
Conclusion
To convert truthy or falsy to an explicit boolean with JavaScript, we use the Boolean function.