val vs var (Kotlin)
In Kotlin, val declares a read-only (immutable) reference that can't be reassigned, while var declares a mutable one that can. Prefer val by default for safer, clearer code.
Kotlin
val (from 'value') creates a binding you can read but not reassign — like final in Java. var (from 'variable') creates a reassignable binding. Both still infer their type, so you rarely write it out.
val makes the reference immutable, not the object. A val list can't be pointed at a different list, but if it's a MutableList you can still add to it. For true immutability you also need an immutable type (List vs MutableList).
Idiomatic Kotlin uses val almost everywhere and reaches for var only when a value genuinely must change. This reduces accidental mutation and makes code easier to reason about, especially with coroutines and concurrency.
Syntax
val name = "Ana" // cannot reassign
var count = 0 // can reassignExamples
Kotlin
val pi = 3.14 // read-only
var score = 0
score = 10 // ok
// pi = 3.15 // compile error
println("$pi $score")Output:
3.14 10