Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

[Author: @mdimamhosen Date: 2025-04-19 Category: interview-qa/boolean Tags: [go, boolean, data-types] ]

A boolean data-type can either be "TRUE" or "FALSE"

package main

import "fmt"

func main() {
	isGolangPL := true
	isHtmlPL := false
	fmt.Println(isGolangPL)
	fmt.Println(isHtmlPL)
}

Frequently Asked Questions

Q1: How can I use boolean values in conditional statements?

Answer: Boolean values are often used in conditional statements to control the flow of a program. For example:

package main

import "fmt"

func main() {
	isEven := true
	if isEven {
		fmt.Println("The number is even.")
	} else {
		fmt.Println("The number is odd.")
	}
}

Q2: Can boolean values be compared directly?

Answer: Yes, boolean values can be compared directly using comparison operators. For example:

package main

import "fmt"

func main() {
	isTrue := true
	isFalse := false
	fmt.Println(isTrue == isFalse) // Output: false
	fmt.Println(isTrue != isFalse) // Output: true
}