Built-in types
Integers
int32 holds whole numbers from -2,147,483,648 to 2,147,483,647. int64 holds whole numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.
Integers never wrap around. A result that doesn’t fit in its type is an overflow error:
Decimals
decimal values are exact. They don’t suffer from the rounding errors of binary floating-point numbers:
decimal(p, s), where p is the maximum number of digits before the decimal point and s is the maximum number after it:
Booleans
boolean has exactly two values, true and false. Conditions in if statements and the operands of !, && and || must be booleans. There is no “truthiness”: if (1) and if ("yes") are errors.
Strings
string holds text. String literals use double quotes and support escapes and interpolation.
Objects
Anobject maps property names to values. Objects are untyped: each property can hold a value of any type, including other objects and lists.
Lists
[]T is a list whose elements are of type T. List types nest, so [][]int32 is a list of lists of integers.
0.
Null
null is a value of every type. You can assign it to any variable, pass it as any parameter or store it as any list element:
Numeric promotion
A numeric value is automatically promoted when a wider type is expected:int32is promoted toint64.int32andint64are promoted todecimal.- An
int64value is accepted whereint32is expected only if it fits in theint32range.