juniorKotlin
What are variables in Kotlin?
Updated May 16, 2026
Short answer
val is immutable, var is mutable.
Deep explanation
val creates read-only references, while var allows reassignment. Kotlin encourages immutability for safer code.
Real-world example
Use val for constants like configuration values.
Common mistakes
- Using `var` everywhere instead of preferring immutability.
Follow-up questions
- Can a val object be modified?
- Why prefer immutability?