By definition, a function is a set or group of related statements that perform a specific task. It is a basic building block of any program. You can equate the function in Kotlin with the method in Java; however, there are certain differences. The function in Kotlin can be defined at the top level, meaning it is not required to be enclosed in a class. The function can be part of a class as well as defined within another function.
In Kotlin, the functions get first-class support, meaning it supports all the operations and can be stored into a variable and data structure, passed as an argument to other function as well as being returned from other (top-level) functions, it can be defined as an expression, and lots more. All these features bring a great amount of flexibility and make Kotlin really concise. We will see the following uses of functions in Kotlin.