Curriculum Types & methods Nil & zero values
Nil & zero values
Every type has a zero value — what an uninitialised variable of that type holds. For numbers: 0. For strings: "". For bools: false. For pointers, interfaces, maps, slices, channels, and functions: nil. nil is *not* TypeScript's undefined — it's a typed absence, and conflating "nil pointer" with "nil interface" is one of the classic Go bugs.
Exercises
9 ready
01
pick one
Every Go type has a defined zero value — what var x T
02
pick one
Only some Go types can hold nil. Numbers, strings, structs,
03
pick one
THE classic Go gotcha. Consider:
04
fill blanks
Type the keyword that represents "no value" for any of Go's
05
type one line
Zero-value-is-useful idiom. A nil slice is fully usable for
06
write a program
Theme capstone — write a complete program that demonstrates
07
pick one
Exercise 5 showed a nil SLICE is fully usable for append.
08
type one line
Range over a nil slice does ZERO iterations — no panic, no
09
write a program
Module 3 capstone. Build a small program that exercises