val vs var
Immutable and mutable bindings.
Two Ways to Name Values
In Scala, you bind a name to a value using either val or var.
val creates an immutable binding: once assigned, it can never point to another value. var creates a mutable binding that you can reassign later.
Choosing between them is one of the first habits a Scala backend engineer builds.
val name = "Ada"
var score = 10Defining a val
A val is read-only. You assign it once, and the compiler guarantees it stays the same.
This makes your code easier to reason about: a val never surprises you with a changed value somewhere else.
object Main extends App {
val pi = 3.14
println(pi)
}