Mahdi.Kh
September 21, 2026
In this part, we get familiar with const in Go and learn how to use constants.
A constant, or const, is like a variable whose value can't change while the program is running. To define constants in Go, we use const along with the name and value we want.
Constants can have whatever type we want. In the example below, we define a constant with type string:
If we specify a data type for a const, we can only use that const in ways that respect that data type:
In the code above, we can see that the value of the constant minuteSeconds can be stored in both the x and y variables, because it has no data type. But the constant dayHours has type int, so its value can't be stored in variable y, because that variable has type int32.
In this part, we got familiar with const. We saw that you can specify a constant's type, which makes it behave differently when it's used.
Previous part: Variables | Golang basics
Next part: Numbers | Golang basics