🐦 Kotlin Beginner

What is a named argument in Kotlin?

Answer

Named arguments allow you to specify the parameter name when calling a function, which lets you pass arguments in any order and makes the code self-documenting. Example: fun createUser(name: String, age: Int, admin: Boolean = false) can be called as createUser(age = 25, name = "Alice"). Named arguments are particularly valuable for functions with multiple parameters of the same type or boolean flags, where positional arguments make the call site confusing. They also let you skip any subset of default parameters.