JavaScript Boolean() function explained

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

Take your skills to the next level ⚡️

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

No spam. Unsubscribe anytime.