A focused look at two special cases for map index expressions in Go. First, the two-value assignment form (v, ok := a[x]) returns an additional boolean indicating whether a key exists, which helps distinguish between a missing key and a key explicitly set to the zero value. Second, while reading from a nil map is valid and returns the zero value, assigning to a nil map causes a runtime panic. Code examples illustrate both behaviors clearly.

2m read timeFrom boldlygo.tech
Post cover image
3 Impressions