"nil slice" vs "nil map"
Slice and map are all reference types in Go, and their default values are nil:
package main import "fmt" func main() { var ( s []int m map[int]bool ) if s == nil { fmt.Println("The value of s is nil") } if m == nil { fmt.Println("The value of m is nil") } } The result is like this:
The value of s is nil The value of m is nil When a slice’s value is nil, you could also do operations on it, such as append:
[Read More]