Constants are a way to create a named identifier whose value can never change. They also provide an incredible amount of flexibility to the language. The way constants are implemented in Go is very unique.
- Constants are not variables.
- They exist only at compilation.
- Untyped constants can be implictly converted where typed constants and variables can't.
- Think of untyped constants as having a Kind, not a Type.
- Learn about explicit and implicit conversions.
- See the power of constants and their use in the standard library.
https://golang.org/ref/spec#Constants
http://blog.golang.org/constants
http://www.goinggo.net/2014/04/introduction-to-numeric-constants-in-go.html
Declare and initialize constants (Go Playground)
Parallel type system (Kind) (Go Playground)
iota (Go Playground)
Implicit conversion (Go Playground)
Part A: Declare an untyped and typed constant and display their values.
Part B: Divide two literal constants into a typed variable and display the value.
Template (Go Playground) | Answer (Go Playground)
All material is licensed under the Apache License Version 2.0, January 2004.