Golang: Zero Value
What is Zero Value
- Zero Value is the default value for a variable.
- Default value are different for different types.
- Variables declared without an explicit initial value are given their default value.
Possible Zero Values
0
- for numeric types
false
- for boolean type.
""
- (empty string) for string type.
nil
- for pointers, functions, interfaces, slices, channels, and maps.
package main import "fmt" func main() { var i int var f float64 var b bool var str string var sl []int fmt.Println(i == 0) fmt.Println(f == 0) fmt.Println(b == false) fmt.Println(str == "") fmt.Println(sl == nil) }