[Golang] Why Go Variables Have Zero Values Instead of Being Uninitialized

go dev.to

Consider this Go program: package main import "fmt" func main() { var count int var enabled bool var name string fmt.Println(count) fmt.Println(enabled) fmt.Println(name) } It prints: 0 false We never assigned anything to these variables. So why do they already have values? Because in Go, a variable is never in an uninitialized state. If you don't provide an initial value, Go gives it the type's zero value. This sounds like a small language featur

Read Full Tutorial open_in_new
arrow_back Back to Tutorials