11. Constants
Can not change me
What are constants?
A const
declaration defines named values that look syntactically like variables but whose value is constant.Instead of the var
keyword, we use the const
keyword.A value must be assigned while declaring constants.Constants only exists during compile time!
Declaring constants
Constants are declared using const
keyword.
main.go
Constant Block
Similar to variable block, we can also have constant block.
main.go
IOTA
iota
can be used to create enumerated constants. It is also called as constant generator.
main.go
Benefits of using iota is that it will increment itself for next const declaration in same const block.
main.go
From the Docs
Blog Posts
Last updated