Boolean
A boolean is a logical data type that can have only two values: true or false.
Booleans are used throughout programming to represent conditions, decisions, flags, and other yes/no logic.
What it does
A boolean stores the result of a logical condition.
It is commonly used to:
- Decide whether code should run
- Control loops and branching
- Store simple enabled/disabled state
- Represent yes/no flags in data
- Express the outcome of comparisons or tests
Core concepts
Two-state logic
A boolean is built around only two possible logical values.
That makes it one of the simplest and most fundamental data types in software.
Condition handling
Booleans are commonly used in if statements, loops, filters, and validation logic.
They often come from expressions such as comparisons or checks.
Boolean vs binary
A boolean is a logical type with two values.
Binary is the broader two-state representation model used throughout computing.
Common use cases
- Feature flags
- Validation results
- Comparison outcomes
- Visibility or enabled/disabled settings
- API fields representing yes/no state
Practical notes
- Many languages represent booleans as
trueandfalse, but exact syntax can vary. - Booleans are conceptually simple, but bugs often happen when truthy/falsy conversion rules are misunderstood.
- A boolean value is different from the string
"true"or"false". - Booleans are frequently used alongside variables, arrays, and conditional logic.
Sources Used
Frequently Asked Questions
Is a boolean the same as binary?
Not exactly. A boolean is a logical two-value type, while binary is the broader base-2 representation model used by digital systems.
Can a boolean hold more than two values?
No. A boolean is specifically a two-state type.
Is "true" the same as true?
No. "true" is text. true is a boolean value.