Flash cards
Review the key moves
1/4
Core idea
What is the main idea behind Go Boolean Data Type?
Lesson checks
Practice each idea before moving on
Short Mimo-style checks built from this lesson's code, terms, and sequence.
1Quick choice
Which statement best captures the main point of this lesson?
2Fill blank
Complete the missing token from the example code.
___ mainBoolean Data Type
A boolean data type is declared with the bool keyword and can only take the values true or false .
The default value of a boolean data type is false .
Example
package main
import ("fmt")
func main() {
var b1 bool = true
// typed declaration with initial value var b2 = true // untyped declaration with initial value var b3 bool // typed declaration without initial value b4 := true // untyped declaration with initial value fmt.Println(b1) // Returns true fmt.Println(b2) // Returns true fmt.Println(b3) // Returns false fmt.Println(b4) // Returns true
}Note
Boolean values are mostly used for conditional testing which you will learn more about in the Go Conditions chapter.