Variables

Use val for a variable whose value never changes.

⚠️ val isn’t a constant

// String type definition
val playerName: String = "Algus Dark"
// ✘ Val cannot be reassigned
playerName = "New Name"

Use var for a variable whose value can change

// 💡 When you assign an initial value the Kotlin compiler
// can infer the type based on the type of the assigned value.
var playerLevel = 2
playerLevel = 3