0PricingLogin
Go Academy · Lesson

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 context
  • const Pi float64 = 3.14159 — typed float64
  • Untyped integer constants can be used with any integer type

All lessons in this course

  1. Declaring Variables in Go
  2. Go's Built-in Types
  3. Constants and iota
  4. Type Conversions in Go
← Back to Go Academy