3.6 Constants
Constants are expressions whose value is known to the compiler and whose evaluation is guaranteed to occur at compile time, not at run time. The underlying type of every constant is a basic type: boolean, string, or number.
A const
declaration defines named values that look syntactically like
variables but whose value is constant, which prevents
accidental (or nefarious) changes during program execution. For
instance, a constant is more appropriate
than a variable for a mathematical constant
like pi
, since its value won’t change:
const pi = 3.14159 // approximately; math.Pi is a better approximation
As with variables, a sequence of constants can appear in one declaration; this would be appropriate ...
Get The Go Programming Language now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.