Function

A series of instructions that are grouped and callable by a name. The primary components of a function are its:

  • name
  • parameter(s)
  • return value

These three things together are called a function’s signature.

Example

Below is an example Javascript function that adds two numbers:

1
2
3
function addValues(a, b) {
    return a + b;
}

Here is an example Kotlin function that finds the smallest value in a list:

1
2
3
4
5
6
7
8
9
fun smallestValue(value: List<Int>): Int {
    var smallest = value.first()
    value.forEach {
        if (it < smallest) {
            smallest = it
        }
    }
    return smallest
}

A Note on Go

Go, the programming language created by Google, permits multiple return values.

Further Reading