:= (short declaration)
Defines a variable and automatically infers its type.
Syntax
name := value
Description
Most commonly used definition inside functions. No type is given, it is determined by the value.
Example
Loading editor…
Expected output
Alex 36
When to use?
Local variable definition.
Common mistakes
- ⚠️ := is only inside functions; use var at the package level.
- ⚠️ An unused variable is an ERROR in Go.