HTML CSS JavaScript SEO Python Posts Privacy About Contact

JS Booleans

A JavaScript Boolean represents one of two values: true or false.

Very often, in programming, you will need a data type that can only have one of two values, like:

  • YES / NO
  • ON / OFF
  • TRUE / FALSE

For this, JavaScript has a Boolean data type. It can only take the values true or false.

The Boolean() Function

You can use the Boolean() function to find out if an expression (or a variable) is true.

Preview

Or even easier:

Preview

Comparisons and Conditions

Booleans are strictly used in comparisons and conditions. The following is an introduction to truthy and falsy values.

Everything With a “Value” is True

Preview

Everything Without a “Value” is False The Boolean value of 0 (zero), -0 (minus zero), "" (empty string), undefined, null, and false, is false.

Preview