DEV Community

indiewebdev
indiewebdev

Posted on

Golang Notes - 15

Scopes

scope = visibility

there are 3 scopes

  • file scope
  • package scope
  • block -local- scope
import "fmt" // file scope

import f "fmt" // alias import

const pi = 3.14 // package scope

func main() {
  x := 10 // local(block) scope
  f.Println(x)
  fmt.Println(x)
}
Enter fullscreen mode Exit fullscreen mode
  • import statements are file scoped

Top comments (0)