Constants and iota
Defining constants and using iota for enumerations
What Are Constants?
A constant stores a value that never changes at runtime.
- Declared with
const - Must be computable at compile time
- Can be typed or untyped
- String, boolean, numeric, and rune literals are allowed
Typed vs Untyped Constants
Untyped constants have higher precision and are more flexible:
const Pi = 3.14159— untyped float, adapts to contextconst Pi float64 = 3.14159— typed float64- Untyped integer constants can be used with any integer type
All lessons in this course
- Declaring Variables in Go
- Go's Built-in Types
- Constants and iota
- Type Conversions in Go