Course contentsShow
← JavaScript
Lesson 34 of 2,7232. Values and TypesFree lesson

Boolean: true and false

Explore the boolean type and how it represents logical truth values in JavaScript.

Boolean: true and false

What you'll learn: How JavaScript uses the boolean type to represent yes/no, on/off, and true/false values.

What is a Boolean?

The boolean type is one of JavaScript's seven primitive types, and it's beautifully simple: it can only be one of two values — true or false. That's it!

Think of a boolean like a light switch. It's either on (true) or off (false). There's no in-between, no "kind of on" or "mostly off." This binary nature makes booleans perfect for representing logical states and making decisions in your programs.

Why Booleans Matter

Booleans are the foundation of logic in programming. They answer questions like:

  • Is the user logged in? (true or false)
  • Is the value undefined? (true or false)
  • Has the form been submitted? (true or false)

Boolean Values in Action

You can assign boolean values directly:

console.log(true);   // true
console.log(false);  // false

Notice there are no quotes around true and false — they're not strings like "true" or "false". They're actual boolean values, a distinct primitive type in JavaScript.

True vs "true"

This is a crucial distinction: true (a boolean) is completely different from "true" (a string that happens to contain the word "true"). One represents a logical truth value; the other is just text.

Key Takeaway: Booleans are JavaScript's way of representing logical truth with exactly two possible values: true and false. They're essential for making decisions and controlling program flow.