Golang: Zero Value

By Xah Lee. Date: . Last updated: .

What is Zero 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)

}

Golang, Types and Values