Skip to content
Justice Tech School

Functions

fun declares a function. A single expression can use =. Unit means no value.

Example
fun add(a: Int, b: Int): Int = a + b
fun greet(name: String) { println("Hello $name") }
println(add(2, 3))
greet("Ada")

Exercise

Short body.

fun f(x: Int)  x * 2

Quiz Test

What does Unit mean?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.