Zero values
Every variable in Go has a type, and every type has a zero value.
| Type | Zero value |
|---|---|
int | 0 |
float64 | 0 |
bool | false |
string | "" |
| pointer | nil |
If you declare var age int without assigning, age is already 0 and safe to use.
Type inference
When you use :=, Go works out the type from the literal:
name := "Ada" // inferred as string
age := 30 // inferred as int
pi := 3.14 // inferred as float64
This is called type inference. It keeps code short but means you should pick literal types carefully, 30 is an int, not a float.