Constants
A constant is a labeled box that never changes.
Once you put a value in, it stays locked.
Use it for fixed things like max users, app names, or math numbers.
Declaring with const
Use the const keyword.
Unlike a variable, you cannot give a constant a new value later.
If you try, Go stops you.
Typed and untyped constants
A constant can have a type written next to it.
Or it can wait with no type yet.
Untyped ones stay flexible until you use them somewhere that needs a real type.
Const blocks
You can group related constants in one const block.
That keeps fixed values easy to find.
iota for counting lists
Inside a const block, iota starts at 0.
It goes up by one on each new line.
It is handy for lists like days of the week.
When to use const
Use const when the value must not change.
Use a variable when the value may change later.
Constants stay locked. The compiler stops you if you try to change them.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.