Types are life. – Bill Kennedy
Go is statically typed. It means that variables always have specific type and the type cannot change during the program run time.
Data types help us reason about what our program is doing and help us catch many errors.
Types classify values into groups and determine:
- what is the memory size allocated for the value
- what does the value represent (e.g. bits
11111111
represent decimal number 255 if the type isint
) - what are intrinsic operations of that representation (e.g. arithmetic operations for numbers,
len
for strings)
Go’s types categories:
- basic types: numbers (integers, floats, complex), strings, booleans
- aggregate types: arrays, structs (user-defined types)
- reference types: pointers, slices, maps, functions, channels
- interface types
See also Basic types, Zero values, Type conversions and Type inference.