Storing to a Nil Map

Let’s learn how to store data to a nil map.

We'll cover the following

Now, let’s discuss a special case where a map variable has the nil value. We are allowed to assign a map variable to nil. In that case, we will not be able to use that variable until we assign it to a new map variable. Put simply, if we try to store data on a nil map, our program will crash.

Coding example

This is illustrated in the next bit of code, which is the implementation of the main() function of the nilMap.go program.

Get hands-on with 1200+ tech skills courses.