Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Default values of variables

  • false

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

  • 0 for numeric types.
  • "" (the empty string) for strings.
  • false for the boolean type.
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
}
0
0

false