It's not the same if you intend to store the zero value of the value type.
See this example:
m := map[string]string{
"empty": "",
}
if v, ok := m["empty"]; ok {
fmt.Printf("'empty' is present: %q\n", v)
} else {
fmt.Println("'empty' is not present")
}
if v, ok := m["missing"]; ok {
fmt.Printf("'missing' is present: %q\n", v)
} else {
fmt.Printf("'missing' is not present")
}
It outputs (try it on the Go Playground):
'empty' is present: ""
'missing' is not present
It's true that if you never store the zero value in the map, you may simply use if m[value] == zeroValue {}
. This is detailed here: How to check if a map contains a key in Go?
This "property" of maps can be exploited to create sets elegantly. See How can I create an array that contains unique strings?
And using this "technique" has another advantage too: you can check existence of multiple keys in a compact way (you can't do that with the special "comma ok" form). More about this: Check if key exists in multiple maps in one condition