Values and Variables in Go
A value is a piece of data, like ‘Hello, World!’. Values have types: the type of ‘Hello, World!’ is named string
. So we call this a string value.
A variable is a name identifying a particular place in the computer’s memory that can store some specific value. A variable (in Go and other programming languages like C and Haskell) also has a type, which determines what values it can hold.
A string variable can only hold string values, etc.
In Go, we declare a variable and its type with the following syntax
1var title string
2var copies int
The Go compiler will use the type information you’ve provided to check whether you accidentally assigned a value to the wrong type of variable.
References
- John Arundel, For the love of Go
Next -> zero-values-and-default-values-in-go
Next -> composite-values-and-structs-in-go
Next -> shorthand-assignment-in-go