typeover
curriculum

Curriculum Idioms & ecosystem Common gotchas exercise 1 · mcq

Common gotchas

Interface nil vs concrete nil — Go's most-famous trap. Pick the line that prints, after func returnsError() error { var p *MyErr; return p } is called: ``go err := returnsError() if err == nil { fmt.Println("ok") } else { fmt.Println("bad:", err) } ` (*MyErr satisfies the error interface via its Error() method.) TypeScript: null is null`; no interface/concrete asymmetry. Go's interface variable holds (type, value); it's nil only if BOTH are nil.

TypeScript reference
Pick the idiomatic Go translation

About this theme

The "what bit me in code review" survival kit:

  • Loop variable capture (Go 1.22+ helped, but you should still know).
  • Nil interface vs nil concrete (a non-nil pointer inside an interface variable makes the interface non-nil).
  • Slice aliasing — two slices sharing a backing array.
  • Goroutine leaks — a goroutine waiting on a channel that nobody will ever send to.