A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

Boolean Type and Truth Values

College Depth 69 in the knowledge graph ☐ I know this ☆ Set as goal
975topics build on this
312prerequisites beneath it
See this on the map →
Memory, Data Storage, and VariablesBoolean Algebra+1 more→→BDD-Based VerificationComparison Operators and Boolean Tests+7 more
types boolean logic

Core Idea

The boolean type represents two values: true and false. Booleans are produced by comparisons and logical operations, and are used to make decisions in programs through conditionals and loops.

How It's Best Learned

Write expressions that evaluate to true or false. Explore how different comparisons produce booleans.

Common Misconceptions

Explainer

You already understand that computers store data in memory and that variables hold values. The boolean type is the simplest data type possible: it has exactly two values, true and false. Named after mathematician George Boole, booleans represent the answers to yes-or-no questions. Is 5 greater than 3? True. Is "hello" equal to "goodbye"? False. Every comparison you write in a program produces a boolean result.

Booleans are created most often through comparison operators. When you write `x > 10`, the computer evaluates this expression and produces either true or false depending on the current value of x. The expression `temperature == 100` checks equality and produces true or false. These comparisons — greater than, less than, equal to, not equal to — are the basic building blocks that generate boolean values. The key insight is that the result of a comparison is itself a value, just like the number 42 or the text "hello". You can store it in a variable: `is_adult = age >= 18` puts either true or false into `is_adult`.

What makes booleans powerful is that they are the language of decisions in programs. Every time a program chooses between two paths — should I show an error message or continue? should I keep looping or stop? — it evaluates a boolean expression. The `if` statement you'll encounter next takes a boolean and executes one block of code when it's true and optionally another when it's false. Loops repeat as long as a boolean condition remains true. Without booleans, programs would execute the same instructions every time with no ability to respond to different situations.

A common source of confusion is the relationship between booleans and numbers. In many languages, true behaves like 1 and false like 0 when used in arithmetic, and non-zero numbers are treated as "truthy" in boolean contexts. But treating booleans as mere numbers misses their purpose. A boolean carries meaning — it represents a logical proposition, not a quantity. The variable `is_logged_in` communicates intent in a way that the number 1 never could. As you move into logical operators and conditionals, thinking of booleans as answers to questions rather than as numbers will make your code clearer and your reasoning more precise.

Practice Questions 5 questions

Prerequisite Chain

Understanding Zero → The Number Zero → Counting to Five → Counting to 10 → Counting to 20 → Counting a Set of Objects Up to 20 → Cardinality: The Last Number Counted → Matching Numerals to Quantities → Subitizing Small Quantities → Addition Within 10 → Number Bonds to 10 → Addition Within 20 → Doubles and Near Doubles → Doubles Facts Within 10 → Near Doubles Facts Within 20 → Mental Math Strategies for Addition → Mental Math: Adding and Subtracting Tens → Addition Within 100 → Repeated Addition as Multiplication → Multiplication as Equal Groups → Multiplication: Arrays → Basic Multiplication Facts (0s, 1s, 2s, 5s, 10s) → Multiplication Facts Within 100 → Division as Equal Sharing → Division as Grouping (Measurement Division) → Division: Grouping (Repeated Subtraction) Model → Division: Fair Sharing Model → Division as Equal Sharing → Division as Grouping → Basic Division Facts → Division Facts Within 100 → Multiplication and Division Fact Families → Relationship Between Multiplication and Division → Division Facts as Inverse of Multiplication → Remainders and Quotients in Division → Division Word Problems → Multi-Step Word Problems → Solving Multi-Step Word Problems → Multiplication Word Problems → Division Word Problems → Introduction to Long Division → Factors and Multiples → Prime and Composite Numbers → Equivalent Fractions → Relating Fractions and Decimals → Decimal Place Value → Integers and the Number Line → Comparing and Ordering Integers → Absolute Value → Adding Integers → Subtracting Integers → Multiplying Integers → Introduction to Exponents → Order of Operations → Integer Order of Operations → Variable Expressions → The Distributive Property → Variables and Expressions Review → Introduction to Polynomials → Adding and Subtracting Polynomials → Multiplying Polynomials → Factorial → Permutations → Combinations → Counting Principles: Addition and Multiplication Rules → Introduction to Graph Theory → Propositional Logic Foundations → Logical Equivalences → Boolean Algebra → Boolean Type and Truth Values

Longest path: 70 steps · 312 total prerequisite topics

Prerequisites (3)

Leads To (9)