← BYTES
Go·Starter·Ref: 10.1.15
What is the zero value of a map variable, and what happens if you try to write to it in that state?
Have a question about this video? Mention reference 10.1.15 when you contact us.
a.An empty-but-usable map; writing to it works fine immediately
b.A compile-time error -- maps can never be left uninitialized
c.0; maps are secretly just integers under the hood
d.nil; writing to a nil map panics at runtime, though reading from it is safe and just returns zero values
A declared-but-unassigned map is nil, not an empty, ready-to-use map. Reading from a nil map is perfectly safe (every key lookup just returns the zero value as if absent), but writing to a nil map panics -- which is why map creation typically uses make(map[K]V) or a map literal before any writes.
Find this on YouTube & Instagram
Every BYTES video is tagged with its reference number and topic — search any of these on YouTube or Instagram to find this one:
#BYTES#BYTES10115#Go