Skip to content
Learn Netverks

Lesson

Step 17/36 47% through track

maps-go

Maps

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

This lesson

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

Slices and maps are reference types—capacity, nil safety, and iteration pitfalls appear in every code review.

You will apply Maps 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.

Maps are hash tables: map[string]int. Keys must be comparable types. Like Python dicts or Java HashMaps—O(1) average lookup.

Creating and accessing

ages := map[string]int{"Ada": 36}
ages["Grace"] = 89
v, ok := ages["Unknown"]  // ok false if missing

Reading a missing key returns zero value without panic—use comma-ok or delete intentionally. Maps are reference types; nil maps cannot be written to until initialized with make.

Iteration

for k, v := range m order is randomized—do not depend on key order for logic.

Important interview questions and answers

  1. Q: Zero value of map?
    A: nil—assignments panic until make(map[K]V) or literal.
  2. Q: Concurrent map access?
    A: Not safe—use sync.Map or mutexes; or one goroutine owns the map.

Self-check

  1. How do you test if a key exists?
  2. Is map iteration order stable?

Pitfall: Writing to a nil map panics—initialize with make(map[K]V) or a literal before assignment.

Interview prep

Nil map write?

Panics—initialize with make or literal before assignment.

Map iteration order?

Randomized—never depend on key order for logic.

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

  • Map zero value?
  • Concurrent map safe?

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