JS-030
JavaScript diagram about Boolean(): a visual example of Converting to true or false
Beginner4 min~4 min read#boolean#type-conversion#truthy

Boolean()

Converting to true or false

Goal

Learn how to convert values to true or false using Boolean().

Explanation

  • Boolean() converts any value to the boolean type.
  • The result is always either true or false.
  • Most values in JavaScript convert to true.
  • Some special values, such as 0 or an empty string, convert to false.
  • Boolean() is very important for conditions and program logic.

Analogy

Imagine a guard at the entrance. They check any value and make only one of two decisions: yes (true) or no (false).

Code

console.log(Boolean(1));
console.log(Boolean(0));
console.log(Boolean("Hello"));
console.log(Boolean(""));

Result: true false true false

Common mistake

Beginners often think any text means false. In reality, even the string "false" converts to true because it is not empty.

Remember

  • Boolean() returns true or false.
  • 0 converts to false.
  • An empty string converts to false.
  • Most other values become true.

Quick Quiz

What does Boolean(0) return?

Resources