Among all the many keywords that Kotlin comes with, there exists
var. What are they used for? What are the differences, and why would you use one over another?
They are both used to declare variables in Kotlin. But how are they different?
val is used to declare a variable that is read-only, and who’s value does not change.
Note that this only applies to the parent variable, and not it’s properties. The properties of the variable are still mutable.
var is also used to declare a variable. However, its value can be mutable.
var is used to declare a variable that can be changed. It can also be assigned multiple times.