Boolean Data Type
You'll learn how to store and work with true/false values that represent logical conditions in your programs.
What Is a Boolean?
A boolean (named after mathematician George Boole) is a data type that can hold exactly one of two values: true or false. That's it—no numbers, no text, just these two logical states.
Think of a boolean like a light switch: it's either ON or OFF, never halfway. In programming, booleans let you represent yes/no questions, conditions that are met or not met, and decisions your program needs to make.
Why Booleans Matter
Remember all that logic you learned—propositions, truth tables, AND/OR operations? Booleans are how those concepts come alive in actual code. Every time you check "Is the user logged in?" or "Is this number greater than 10?" you're working with boolean values.
When you declare a boolean variable, you're creating a container that stores a truth value:
isRaining = true
hasPermission = false
isPositive = (5 > 0) // evaluates to true
The third example shows how comparisons naturally produce boolean results. The expression 5 > 0 asks a yes/no question, and the answer (true) gets stored in isPositive.
Boolean Operations
Booleans work with the logical operators you already know: AND, OR, NOT. These let you combine simple true/false conditions into more complex logical statements, exactly like you did with propositional logic.
Key Takeaway: Booleans are the programming world's way of storing true/false values, letting you represent logical conditions and make decisions in your code based on whether something is true or false.