JS-006
JavaScript diagram about Boolean: a visual example of True or False
Beginner2 min~2 min read#boolean#true#false

Boolean

True or False

Goal

Learn how JavaScript stores true and false values.

Explanation

  • Boolean is a data type that can hold only two values: true or false.
  • It is used when the answer can only be "yes" or "no".
  • For example: is the door open or closed, is the user logged in, is the product available.
  • Boolean is very important for conditions and decision-making in a program.
  • Almost every if statement checks a boolean value.

Analogy

Boolean is like a light switch. It can only be in two states: on or off.

Code

let isOpen = true;
let isLoggedIn = false;

console.log(isOpen);

Result: true

Common mistake

Do not confuse the boolean true with the string "true". The first is a logical value; the second is plain text.

Remember

  • Boolean has only two values.
  • true means "yes".
  • false means "no".
  • Boolean is used for program logic.

Quick Quiz

How many values does the Boolean type have?

Resources