Go is a statically typed language. Every variable has a specific type that is known at compile time.
var age int = 30
name := "GoLang"
price := 99.99
isActive := trueint, int8, int16, int32, int64uint, uint8 (alias for byte), uint16, etc.float32, float64complex64, complex128boolstringrune (alias for int32, used for Unicode characters)If a variable is declared without initialization, it gets a default zero value:
int → 0bool → falsestring → ""pointer/slice/map/function/interface → nilvar x int
var s string
fmt.Println(x) // 0
fmt.Println(s) // ""When you use :=, Go automatically infers the type from the right-hand side:
a := 42 // int
b := 3.14 // float64
c := "hello" // string
d := true // boolGo does not allow implicit type casting — you must convert manually:
var i int = 42
var f float64 = float64(i)
var s string = fmt.Sprint(i)Note: Conversion must be explicit even between compatible types like int32 and int64.
type declarations allow you to create new named types or type aliases for better readability, structure, and domain modeling in your programs
This is useful when building clear domain-specific models.
Ask the AI if you need help understanding or want to dive deeper in any topic