

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 5
click for more info
Not enough gems
Cost: 6 gems
1: Learn Go
incomplete
2: Declaring a Variable
incomplete
3: Basic Variables
incomplete
4: Short Variable Declaration
incomplete
5: Why Go?
incomplete
6: Comments
incomplete
7: The Compilation Process
incomplete
8: Fast and Compiled
incomplete
9: Type Sizes
incomplete
10: Which Type Should I Use?
incomplete
11: Go Is Statically Typed
incomplete
12: Compiled vs. Interpreted
incomplete
13: Same Line Declarations
incomplete
14: Small Memory Footprint
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Sad variable declaration:
var mySkillIssues int
mySkillIssues = 42
GOATed variable declaration:
mySkillIssues := 42
The walrus operator, :=, declares a new variable and assigns a value to it in one line. Go can infer that mySkillIssues is an int because of the 42 value. Yay type inference!
The :=, (walrus operator) should be used instead of var style declarations basically anywhere possible. The limitation is that := can't be used outside of a function (in the global/package scope which we'll talk about later).
Type inference is based on the value being assigned.
An int:
mySkillIssues := 42
A float64:
pi := 3.14159
A string:
message := "Hello, world!"
A bool:
isGoat := true
A common use case for Textio is to send birthday messages.