How do you declare variables in Go?

Beginner

Answer

Go provides multiple ways to declare variables:

// Explicit type declaration
var name string = "John"
var age int = 30

// Type inference
var name = "John"
var age = 30

// Short variable declaration (inside functions only)
name := "John"
age := 30

// Multiple variable declaration
var a, b, c int = 1, 2, 3
x, y := 10, "hello"