Skip to main content

Boolean Data Type

Use the bool keyword when a variable only ever needs to answer yes or no. Just two values exist for this type: true and false.

A boolean that you declare but never assign starts out as false.

Example

The four variables below are declared in different ways. Notice that b3 has no starting value, so it prints false:

Prompt
Declare boolean variables in four ways: typed with value, untyped with value, typed without value, and short declaration. Print all four.
Output: Go program and captured output