Overview - Variables (val, var) and null safety
What is it?
In Kotlin, variables store data that your app uses. You declare variables with val or var. Val means the value cannot change after it is set, like a fixed address. Var means the value can change, like a mailbox where letters come and go. Kotlin also has null safety, which helps prevent errors when a variable might have no value, called null.
Why it matters
Without clear rules for variables and null safety, apps can crash unexpectedly when they try to use missing data. Kotlin’s val, var, and null safety protect your app from these crashes by making you handle data carefully. This leads to more stable apps that users trust and enjoy.
Where it fits
Before learning this, you should understand basic programming concepts like data types and simple variables. After this, you can learn about functions, classes, and how to handle more complex data safely in Kotlin.