Default values of variables


Variables declared without an explicit initial value are given their zero value as default.


examples/zero/zero.go
package main

import "fmt"

func main() {
	var n int
	var f float64
	var s string
	var b bool

	fmt.Println(n) // 0
	fmt.Println(f) // 0
	fmt.Println(s) //    (empty string)
	fmt.Println(b) // false
}

examples/zero/zero.out
0
0

false