Scope and initialization

Lexical scope

Scope describes where a name can be used. A local variable becomes visible after its declaration and remains visible to the end of its block except where shadowed. Scope is distinct from object lifetime. Example output: 'inner\noutside'.

Formal Syntax & Structure

go syntaxgo
{ declarations; statements }

Working Example

Example Snippetgo
package main
import "fmt"
func main() {  {    label := "inner"    fmt.Println(label)  }  fmt.Println("outside")}
Go Reference