Boolean is a data type with two possible values: true and false.
Booleans are commonly used to represent the result of a condition, comparison, predicate, or flag.
For example:
isReady := true
isEmpty := len(items) == 0Booleans are used in:
- Conditional logic
- Loop conditions
- Feature flags
- Predicate functions
Some languages also have truthy and falsy values, where non-boolean values are treated like booleans in conditional expressions. This is different from a strict boolean type.
Anki
id: boolean-truthy-falsy deck: Computer Science::Data Types tags: data-types boolean truthy-falsy
Q: How is a strict boolean different from truthy and falsy values?
A: A strict boolean has only true and false, while truthy and falsy rules treat non-boolean values as booleans in conditions.