Variables
Learn about variables in Go.
We'll cover the following...
We'll cover the following...
Unused variables
Go programs with unused variables do not compile:
“The presence of an unused variable may indicate a bug […] Go refuses to compile programs with unused variables or imports, trading short-term convenience for long-term build speed and program clarity.”
https://golang.org/doc/faq
Exceptions to that rule are global variables and function arguments:
Short variable declaration
Short variable declarations only work inside functions:
They also don’t work when setting field values: