Welcome To Golang By Example

Multiple constant declarations in Go (Golang)

Overview

Below are some of the ways of declaring multiple constant together

Declaring multiple const together with different value and type

const (
  a = "circle"
  b = 1
  c float = 4.65
)

The declaration can be typed or untyped. Refer to this article to understand the difference between typed and untyped constant – https://golangbyexample.com/typed-untyped-constant-golang/

Declaring multiple const together with same value and type

const (
  a string = "circle"
  b
)

When constant type and value is not provided, then it gets its type and value from previous declaration

Combining above two

const (
  a string "circle"
  b
  c = 1
)

Multiple declaration in single line

const a, b = 1, 2
const c, d int = 3, 4

Declaration again can be typed or untyped