var declaration

The Go statement that declares a variable with the var keyword, optionally giving its type and a starting value.

In more detail

Use var at package level, where := is not allowed, and when you want an explicit type or the zero value, as in var retries int64 = 3 or var enabled bool. An unused local variable is a compile error in Go, not a warning.

Examples

var retries int64 = 3
var hosts []string  // nil slice

Related terms

Taught in

References