Skip to main content
The bool type in Go is a predeclared, strictly typed primitive representing a boolean truth value. It is restricted to exactly one of two universe block identifiers: true or false.

Memory and Architecture

A bool in Go occupies exactly 1 byte (8 bits) of memory, regardless of the underlying system architecture (32-bit or 64-bit).

Zero Value

The zero value for an uninitialized bool is false.

Strict Type Safety

Go enforces strict type boundaries for booleans. Unlike C or Python, Go does not treat numeric values (like 0 or 1) or nil pointers as truthy or falsy. A bool cannot be implicitly or explicitly converted to or from any numeric type.

Operators and Evaluation

The bool type supports logical and equality operators. Go employs short-circuit evaluation for logical operators, meaning the right-hand operand is only evaluated if the left-hand operand does not definitively determine the overall expression’s result.
  • Logical AND (&&): Yields true if both operands are true. Short-circuits if the left operand is false.
  • Logical OR (||): Yields true if either operand is true. Short-circuits if the left operand is true.
  • Logical NOT (!): Unary operator that negates the boolean value.
  • Equality (==, !=): Compares two boolean values.

String Formatting

When interacting with the fmt package, the specific format verb for a bool is %t.

Type Definition

When creating a new defined type based on bool, the new type inherits the memory footprint and boolean characteristics but becomes a distinct type. It loses implicit type compatibility with the predeclared bool and requires explicit conversion. This differs from a true type alias (type FeatureFlag = bool), which would remain completely interchangeable.
Tired of Poor Go Skills? Fix That With Deep Grasping!Learn More