Skip to content
Learn Netverks

Lesson

Step 8/36 22% through track

constants-iota

Constants and iota

Last reviewed May 28, 2026 Content v20260528
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
beginner

This lesson

This lesson teaches Constants and iota: the syntax, patterns, and safety habits you need before advancing in Go.

Teams still ship Constants and iota in Go codebases—skipping it leaves gaps in debugging and code reviews.

You will apply Constants and iota in contexts like: Kubernetes ecosystem tools, cloud APIs, and CLI utilities.

Write Go in main.go with package main and func main(), click Run on server—the dev runner runs go run main.go; use fmt.Println for output (requires Go toolchain; LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

const declares compile-time constants. Go constants can be untyped numeric literals that adapt to context—unlike Java final fields that are still typed variables.

Basic constants

const Pi = 3.14159
const Greeting = "hello"

Constants cannot be reassigned. They may use expressions of other constants as long as values are computable at compile time.

iota enumerations

const (
    Sunday = iota  // 0
    Monday         // 1
    Tuesday        // 2
)

iota resets to 0 in each const block and increments per line—idiomatic for enums and bitmasks.

Important interview questions and answers

  1. Q: What is iota?
    A: A counter in const blocks starting at 0, incrementing each line—used for enumerations and flags.
  2. Q: const vs var?
    A: const values are fixed at compile time; var can change at runtime.

Self-check

  1. What value does the second iota line get in a block?
  2. Can a const hold a slice?

Tip: Each const block resets iota to 0—start a new block when defining unrelated enumerations.

Interview prep

What is iota?

A counter in const blocks starting at 0, incrementing per line—idiomatic for enumerations.

Can const be a slice?

No—constants must be compile-time representable; slices are not constant.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • const block?
  • iota reset?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump