Go Boolean Data Type

The Boolean data type in Go is declared using the bool keyword. It represents two values:

Tutorials dojo strip
  • true
  • false

The default value of a Boolean variable is false.




Example: Declaring Boolean Variables

This example demonstrates various ways to declare Boolean variables:

package main

import ("fmt")

func main() {
    var hasMotorcycleLicense bool = true // Typed declaration with initial value
    var wearsHelmet = true               // Untyped declaration with initial value
    var isInsured bool                   // Typed declaration without initial value
    isReadyToRide := true                // Untyped declaration with shorthand syntax

    fmt.Println(hasMotorcycleLicense)    // Outputs true
    fmt.Println(wearsHelmet)             // Outputs true
    fmt.Println(isInsured)               // Outputs false
    fmt.Println(isReadyToRide)           // Outputs true
}

Output:

true  
true  
false  
true  
Tutorials dojo strip
Scroll to Top