LESSON 9

Booleans

Learning objective: Use true/false values to drive decisions.

Understand

Booleans represent yes/no, on/off states.

A boolean is either true or false. Comparisons produce booleans, and logical operators (&&, ||, !) combine them. Booleans are the basis of every decision your program makes.

Analogy: A boolean is like a light switch: it is either on or off.

See It in Action

Combining conditions:

let age = 20;
let ok = age >= 18 && age < 65;
console.log(ok); // true
How it works: && requires both comparisons to be true, so ok is true only when age is between 18 and 65.

Try It Yourself

  1. Store a boolean directly.
  2. Create one from a comparison.
  3. Combine two conditions with &&.

Quick Quiz

What does the && operator require?

Challenge

Write a boolean expression that checks two conditions at once.

Success condition: Your expression returns true only when both conditions hold.