Scala Values

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.

  • The line 3 is the value
  • The line 5 is doing a sum of the integer 2 and the value a
  • On line 7, we see 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.

Reveal more information and clues
Load Exercise