Categories
JavaScript Answers

How to convert truthy or falsy to an explicit boolean with JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *