Functions
Learn how to create and call user-designed functions in your Kotlin programs!
StartKey Concepts
Review core concepts you need to learn to master this subject
Functions
Function Arguments
Default Arguements
Named Arguments
Return Statement
Single Expression Functions
Function Literals
Functions
Functions
fun greet() {
println("Hey there!")
}
fun main() {
// Function call
greet() // Prints: Hey there!
}
A function is a named, reusable block of code that can be called and executed throughout a program.
A function is declared with the fun
keyword, a function name, parentheses containing (optional) arguments, as well as an (optional) return type.
To call/invoke a function, write the name of the function followed by parentheses.
What you'll create
Portfolio projects that showcase your new skills
How you'll master it
Stress-test your knowledge with quizzes that help commit syntax to memory