Scope and initialization

Package initialization dependencies

Package variables initialize in dependency-respecting declaration order before init functions. A variable can depend on a later declaration; an initialization cycle is illegal. Example output: '3 2'.

Formal Syntax & Structure

go syntaxgo
var a = b + 1; var b = 2

Working Example

Example Snippetgo
package main
import "fmt"
var a = b + 1var b = 2
func main() {  fmt.Println(a, b)}
Go Reference