A variable can be considered in two parts. First its name, for instance a
and then its value, for instance, 12
.
In Scala, a variable also has a type, for instance, Int
when it is an integer.
We assigned a value to the Value a
.
2
and the value a
assert
which perform a test if the sum above is equal to 8
Also, important things to keep in mind, val
are immutable. In Scala, if you want a mutable variable, you would have to use the keyword var
.