What are Go's basic types, and what are their zero values?
Quick Answer
Go's basic types are booleans (bool), numerics (int, int8-int64, uint8-uint64, float32/float64, complex64/complex128), strings (string), and a few others like byte (alias for uint8) and rune (alias for int32, a Unicode code point). Every type has a zero value — the value a variable gets when declared without initialization, not null/undefined. Numeric types zero to 0, bool zeros to false, string zeros to "", and pointers/slices/maps/channels/functions/interfaces zero to nil. This means a freshly declared var s string is immediately usable as an empty string, with no null-check needed.
Detailed Answer
Go has no null. Every type has a well-defined zero value instead.
The zero value table
var i int // 0
var f float64 // 0.0
var b bool // false
var s string // "" (empty string, not nil)
var p *int // nil
var sl []int // nil (a nil slice, but len(sl) == 0 works fine)
var m map[string]int // nil (readable, but writing to it panics)
var ch chan int // nil
Why this matters in practice
A struct with no explicit initializer is already fully usable:
type Config struct {
Retries int
Timeout float64
Name string
}
var c Config
fmt.Println(c.Retries, c.Timeout, c.Name) // 0 0 ""
No field is ever an uninitialized garbage value or a null pointer waiting to crash your program. This is one reason Go code has fewer null-check branches than languages where uninitialized means undefined or null.
The one gotcha: nil maps
A nil map behaves like an empty map for reads, but panics on write:
var m map[string]int
fmt.Println(m["x"]) // 0, no panic — reading a missing key is safe
m["x"] = 1 // panic: assignment to entry in nil map
Always initialize a map you intend to write to, with make(map[string]int) or a map literal.