A variable is a name to represent any value. In a computer, it is a name for a slot in the RAM (Random Access Memory).
A variable is a name to represent any value. In a computer, it is a name for a slot in the RAM (Random Access Memory).
Syntax
var [name] : [type] = [value]
val [name] : [type] = [value]
Examples
var str: String = "My First String!"
Since it is a "var," we can change its value.
str = "Changed Value"
We can ignore the type if we declare and initialize the variable in the same line (inferred).
var str = "My First String!"
Data Types
Here are some primitive types available