Tutorials References Exercises Menu
Paid Courses

Go Boolean Data Type

Boolean Data Type

A boolean data type is declared with the bool keyword and can only take the values true or false.


This example shows the different ways of declaring Boolean variables.

package main
import ("fmt")

func main() {
  var b1 bool = true
  var b2 = true //untyped declaration
  var b3 bool //declaration without initial value
  b4 := true //untyped declaration

  fmt.Println(b1) // Outputs true
  fmt.Println(b2) // Outputs true
  fmt.Println(b3) // Outputs false
  fmt.Println(bo4) // Outputs true
Try it Yourself »

Note: Boolean values are mostly used for conditional testing which you will learn more about in the Go Conditions chapter.