Golang: Constant

By Xah Lee. Date: . Last updated: .

Constants are declared like variables, but its value cannot be changed.

const x = 3

Constants can be string, rune, boolean, or numeric values.

Constant must have a value.

package main

import "fmt"

func main() {
	const c1 = 345
	const c2 = true

	fmt.Println(c1, c2) // 345 true
}