Kodebits Day 87: Default Parameters


What is the output?

fun greet(
  name: String = "Guest"
) = "Hi, $name"
fun main() {
  println(greet("Edith"))
  println(greet())
}


Try it in the online Kotlin Playground →

[spoiler title=”Solution”]

Answer:

Hi, Edith
Hi, Guest

Explanation:

Default parameters provide values when arguments aren’t supplied.

[/spoiler]


Further Reading



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *