What if changing one value could fix bugs everywhere in your app instantly?
Why Constant values with const val in Kotlin? - Purpose & Use Cases
Imagine you have to use the same number or text in many places in your Kotlin program, like the maximum number of users allowed or a fixed URL. You write it everywhere by hand.
When you want to change that number or text, you must find and update every single place manually. This is slow and easy to miss, causing bugs and confusion.
Using const val lets you store that fixed value once with a name. Then you use the name everywhere. Change it once, and all uses update automatically.
val maxUsers = 100 // used everywhere as 100 // hard to update all places
const val MAX_USERS = 100
// use MAX_USERS everywhere
// change once, updates allYou can write safer, clearer code that is easy to maintain and update without mistakes.
Think of a game where the maximum score is fixed. Using const val for that score means you can change the max score easily without hunting through all your code.
Use const val for fixed values you never want to change at runtime.
It prevents errors by centralizing the value in one place.
It makes your code easier to read and update.