Keyword
Go var keyword
Declares variables at package or local scope. A type can be inferred from an initializer; without an initializer a declared type supplies its zero value. Unlike :=, var is allowed at package scope. Example prints 0 then 9.
Formal Syntax & Structure
go syntaxgo
var Name [Type] [= expression] | var ( declarations )Working Example
Example Snippetgo
package main
import "fmt"
func main() { var n int fmt.Println(n) n = 9 fmt.Println(n)}