Puzzle 2 Explanation: Map Type
Understand why you can get nil as your output.
We'll cover the following...
We'll cover the following...
Try it yourself
Try executing the code below to see the result for yourself.
Press + to interact
Go (1.16.5)
package mainimport ("fmt")func main() {var m map[string]intfmt.Println(m["Hello"])}
Explanation
The zero value for an uninitialized map is nil
. Some operations on Go’s map
type is nil
safe, meaning they will work with a nil
map without panicking.
Both len
...