Module 01 Β· Go Basics β Lesson 1 of 3 Β· ~11 min
Variables & constants
Two ways to name a value
In Swift you reached for let (can't change) and var (can). Go has the same idea but different spelling, and it leans on type inference even harder.
var name string = "Mochi"β the long form. Spell the type, or drop it and let Go infer.name := "Mochi"β the short form.:=declares and infers in one move. This is Go'slet name = "Mochi", and it's what you'll write nearly all the time inside a function.
The catch: := only works inside a function. At the top level of a file (package scope) you must use var or const. Everywhere else, := is the idiom.