Scala by Example

Scala is a multi-paradigm, static, and strongly typed language on the JVM.

Source

Values

Values are defined using the ‘val’ keyword:

val name: String = "Sherlock"

Result:

name: String = Sherlock

Unlike Variables in Scala, Values cannot change once declared. Reassignment of values will cause a compile time error.

name = "John"
error: reassignment to val
       name = "John"

Hence, Values in Scala are immutable.