Go — Values, Variables, and Constants (basics)

Go has several different value types, these are:

  • String
  • Integer
  • Float
  • Boolean
  • etc.

Here are some examples:

All these values can be assigned to a variable, and saved for later use. Go’s variables are explicitly declared, and the type and value are then used by the compiler to e.g. check for the correctness of types when comparing two variables, or for function calls.

Here are some examples of variables, and the initialization of variables:

For the last part of this article, I will go into “constants”. Constants are values, when initialized, which cannot be changed. In Go, you can initialize different types of constants: numeric, strings, and booleans.

--

--

Nikolaj Johannes Skole Jensen

Fullstack developer living in Denmark. Experience with both Web- and App development.