Default and Named Arguments
Give parameters defaults and name them when calling.
Example
fun box(w: Int, h: Int = 1, unit: String = "cm") = "${w}x$h$unit"
println(box(3))
println(box(3, unit = "m"))
println(box(h = 2, w = 4))Exercise
Name an argument.
box(w = 1, = 2)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.