Defining variables
var [VARIABLE NAME] [TYPE]
- Data types goes after indetifier
- Variables have
nil
by default - Constants can only be bool,string or numbers
- Strings uses double quotes
var x int
var name string
var price = 2 // type is taken from value
const y = 2
var z int = 2
var text string
text = "Hello!"
Variable initialization shortcut
It only works inside functions.
Type is taken from the value.
otherText := "Bye!"
Variable scopes
- Global
- Function
- Block
Immutable and Constant
We can set value of an immutable in runtime.
Value of contants are set in compilation time.
Built-in Data Types
- string
- integer values: int, int8, int16, int32, int64, uint, uint8, uint16,uint32,uint64
- floating point values: float32, float64
- bool
Boolean operators:
==, !=, <, >, >=,<=,&&,||,!
We can work with pointers!