Constants

Constants are values that are known at compile time and cannot be changed once they are declared.

Declaration

Constants are declared with the const keyword. Note that you cannot use the short declaration syntax (:=) with constants.

const pi = 3.14159
const language = "Go"

Key Rules

  • Immutability: Once a constant is declared, its value is fixed.
  • Types: Constants can be primitive types (strings, integers, booleans, and floats).
  • Restrictions: You cannot use complex types like slices, maps, or structs as constants.