Shadowing constants
- constants can be shadowed as well, but it is not a good idea to do so.
examples/const-shadow/const_shadown.go
package main import ( "fmt" ) const pi float32 = 1.1 func main() { fmt.Println(pi) const pi float32 = 2.2 fmt.Println(pi) { pi := 3.3 fmt.Println(pi) pi = 4.4 fmt.Println(pi) } fmt.Println(pi) }
1.1 2.2 3.3 4.4 2.2
It is declared both outside the main function and inside of it.