Files
learning-go-jon-bodner/chapter-2-primitive-types-and-declarations/03_const.go
2022-12-03 18:30:50 +00:00

34 lines
568 B
Go

// constants are used to give names to literals
// There is no way to declare that a value is immutable
// Use constants for hard-coded package level variables
// constants can be typed or untyped
// leave them untyped for flexibility (can use an untyped int constant in a func that takes a float etc)
// or hardcode them if needed
package main
import "fmt"
const x int = 10
const (
idKey = "id"
nameKey = "name"
)
const z = 20 * 10
func main() {
const y = "hello"
fmt.Println(x)
fmt.Println(y)
x = x + 1
y = "bye"
fmt.Println(x)
fmt.Println(y)
}