Dynamic scope or static scope
In the Go programming language specification [1], it says that
Go is lexically scoped using blocks Here is a quick example to demonstrate the static scope in Go
// go run static-scope.go
package main
import "fmt"
var a = 1
func foo(){
a = 2
fmt.Println("in foo, a is", a)
}
func main(){
var a = 0
fmt.Println("in main, a is", a)
foo()
fmt.Println("after foo() call, a is", a)
}
You should see the following result
in main, a is 0
in foo, a is 2
after foo() call, a is 0