Top-level functions

In many of the examples, we've been looking at functions that are not enclosed within any type of class. This is a key feature of functions in Kotlin. Functions may be defined as independent units of execution inside any Kotlin file. Functions defined like this are known as top-level functions and may be fully available to both Kotlin and Java code, depending on their visibility. We'll dive further into top-level functions later in this chapter.

In this section, we introduced Kotlin functions and began exploring how we can work with functions in a variety of ways including as variables, properties, and function arguments. In the next section, we'll dive deeper into how to define Kotlin functions that reduce boilerplate and increase flexibility in how they can be used.