Variables vs Constants

Kotlin asks you one special question before you store something: “Will this change later?“


1. Cannot change: val (Value)

Use this when the value should never change.

val birthYear = 1995
// birthYear = 2000 -> (Error!) cannot change once set.

Translation:

Remember birthYear as 1995 (never change it)

2. Can change: var (Variable)

Use this when the value may change over time.

var age = 20
age = 21 // allowed!

Translation:

Remember age as 20 for now (you might change it later)
Remember age as 21 again

Kotlin figures it out for you

Kotlin is smart: when you give it a number or a string, it infers the type.

val name = "Alex"   // String
val year = 2026     // Int
var isHappy = true  // Boolean

If you want to look professional, you can write the types yourself, but at the beginning, just trust Kotlin.