What starts a scope
Go uses lexical (static) scope as stated in the Go language specification [1]. As mentioned in the specification,
An identifier declared in a block may be redeclared in an inner block. While the identifier of the inner declaration is in scope, it denotes the entity declared by the inner declaration.
Here is a quick example to demonstrate the redeclaring scope in Go.
// go run inner_scope.go
package main
import "fmt"
func main(){
var a = 1
fmt.Println("In main, a is", a)
{
var a = 2
fmt.Println("In the inner scope, a is", a);
}
}
You should expect the following result.
In main, a is 1
In the inner scope, a is 2