JavaScript Boolean() function explained

Posted on Mar 13, 2021

Learn how to turn any value to its boolean equivalent


JavaScript has a built-in Boolean() function that you can use to turn any value into its boolean equivalent.

For example, the following string value z will be converted to true using the Boolean() function:

let bool = Boolean('z');
console.log(bool); // true
console.log(typeof bool); // "boolean"

Passing a truthy value to the function will return true while passing falsy values will return false:

let boolNull = Boolean(null);
console.log(boolNull); // false
console.log(typeof boolNull); // "boolean"

See also: JavaScript truthy falsy values explained

Level up your programming skills

I'm sending out an occasional email with the latest programming tutorials. Drop your email in the box below and I'll send new stuff straight into your inbox!

No spam. Unsubscribe anytime.