Scala Values

A variable can be considered in two parts. First its name, for instanceaand then its value, for instance,12.

In Scala, a variable also has a type, for instance,Intwhen it is an integer.

We assigned a value to the Valuea.

  • The line 3 is the value
  • The line 5 is doing a sum of the integer2and the valuea
  • On line 7, we seeassertwhich perform a test if the sum above is equal to8

Also, important things to keep in mind,valare immutable. In Scala, if you want a mutable variable, you would have to use the keywordvar.

Reveal more information and clues
Load Exercise