Golang: Constant

By Xah Lee. Date: . Last updated: .

Constants are declared like variables, but with the const keyword.

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

package main

import "fmt"

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

        fmt.Println(c1, c2)

}

Numeric Constants

Numeric constants are high-precision values.

An untyped constant takes the type needed by its context.

Reference

The Go Programming Language Specification - The Go Programming Language#Constants