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

Golang Topics

  1. Compile, Run
  2. Package, Import
  3. Function
  4. Variable
  5. Constant
  6. If Then Else
  7. switch/case
  8. Loop
  9. Basic Types
  10. Array
  11. Slice
  12. map

If you have a question, put $5 at patreon and message me.