Mahdi.Kh
September 21, 2026
We get familiar with the boolean data type and go over the operators related to it.
The boolean data type (bool) is used to represent one of two states, true or false. The value true represents the correct state, and the value false represents the incorrect state.
In the example above, we first put the values true and false into the two variables we wanted, and then displayed these two variables' values on the screen.
In the following lines, we defined a boolean variable named isValid. We first showed its default value on the screen, then changed its value to true and displayed it again.
We displayed each variable's type on the screen (this can be done using %T), and finally, we also displayed the size of the isValid variable. In Go, every boolean variable's size is one byte (eight bits).
First note: if we set a variable's value to true or false, the compiler will consider that variable's type to be bool.
Second note: in Go, every data type has a default value called the zero value, which is assigned when a variable is declared without an initial value. This feature means variables in Go always have a valid value, which prevents errors related to initialization. The zero value for boolean variables is false.
The bool type is usually used to build conditions and loops.
To get familiar with comparison operators, take a look at the example below:
The result of a comparison will be a boolean value.
In this part, we got familiar with the bool data type. We saw that we can assign the values true or false to a boolean variable. Also, the initial (zero) value for a boolean variable is false.
Previous part: Numbers | Golang basics
Next part: The String Data Type | Golang basics