Curriculum Idioms & ecosystem Common gotchas exercise 2 · mcq
Common gotchas
Slice aliasing. Pick what prints:
``go
a := []int{1, 2, 3, 4}
b := a[1:3]
b[0] = 99
fmt.Println(a)
``
TypeScript reference
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.