Go TutorialLesson 6Free preview
Go Variables
This lesson is part of Go · All levels
Summary
This lesson teaches declaration of variables in Go using the keyword var, short declaration:=, as well as how to define type explicitly or through type inference. The unvalued variable is filled with zero values according to the data type. Variables can be declared one by one or at a time in a single block.
Key points
- The formal declaration uses var, while the short declaration uses:= within the function
- Go fill the empty variable with zero value: 0 for numbers, "" for strings, false for bool
- Type inference makes Go guess the type of value given
- Declared but unused variables will cause compile error
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.