Skip to main content
Browse topics

Kotlin Basics

Kotlin Functions

Define functions with default, named and vararg parameters, single-expression, local, tailrec and infix functions.

Kotlin FunctionsDefining Function and Its Type Kotlin ProgramA function is a block of code written to perform a task. A Kotlin example with source code and sample output.Kotlin FunctionsSimple Function Example Kotlin ProgramA function is a block of code written to perform a task. A Kotlin example with source code and sample output.Kotlin FunctionsParameterized Function Example Kotlin ProgramA function is a block of code written to perform a task. A Kotlin example with source code and sample output.kotlin functionsDefault Parameters in KotlinFunction parameters can declare default values so callers may omit them. A Kotlin example with source code and sample output.kotlin functionsNamed Parameters in KotlinCallers can pass arguments by parameter name for clarity. A Kotlin example with source code and sample output.kotlin functionsVararg Parameters in KotlinA vararg parameter accepts zero or more values of the same type. A Kotlin example with source code and sample output.kotlin functionsSingle Expression Functions in KotlinWhen a function body is a single expression, you can use the = syntax. A Kotlin example with source code and sample output.kotlin functionsLocal Functions in KotlinA function declared inside another function is called a local function. A Kotlin example with source code and sample output.kotlin functionstailrec Functions in Kotlintailrec marks a recursive function that calls itself as the last operation. A Kotlin example with source code and sample output.kotlin functionsInfix Functions in KotlinAn infix function is called without dot notation between the receiver and argument. A Kotlin example with source code and sample output.

Related topics

Search tutorials