Defining Functions

← Back to documentation


Description

Functions in Jaf are first-class values that can be stored in variables, passed as arguments, and returned from other functions.

Syntax

func name(parameter) expression

Parameters

Return Value

The function itself (can be assigned to variables)

Examples

Simple function

func square(x) x * x
print(square(5))
# Output: 25

Function with block

func factorial(n) {
    if (n == 0) {
        1
    } else {
        n * factorial(n - 1)
    }
}
print(factorial(5))
# Output: 120

Nested functions

func outer(x) {
    func inner(y) x + y
    inner(10)
}
print(outer(5))
# Output: 15

Multiple expressions

func calculate(x) {
    y = x * 2
    z = y + 10
    z / 3
}
print(calculate(5))
# Output: 6.666...

Notes


See Also


© 2026 elliktronic · Jaf Language