0Pricing
Go Academy · Lesson

Declaring Variables in Go

var, :=, and type inference

What Is a Variable?

A variable is a named storage location for a value. In Go, every variable has a type that is fixed at compile time.

  • Go is statically typed — types cannot change at runtime
  • Variables always have a default zero value when not explicitly set
  • Clear naming matters: Go favors short, clear names over long ones

var Declaration

The var keyword declares one or more variables explicitly:

package main

func main() {
    var name string
    var age  int
    var pi   float64 = 3.14
    _ = name
    _ = age
    _ = pi
}

All lessons in this course

  1. Declaring Variables in Go
  2. Go's Built-in Types
  3. Constants and iota
  4. Type Conversions in Go
← Back to Go Academy