# First-Class Function

> A function treated as a value. You can store it, pass it or return it.

**Field:** Software Development  
**Category:** Programming Paradigms  
**Also known as:** First-Class Functions, Functions as Values, First-Class Citizen

## Think of it like

It is like a recipe card you can hand around. You can keep it, pass it on or give it back.

## Definition

A language has first-class functions when a function is treated like any other value. You can store one in a variable. You can pass one into another function, and a function can hand one back. JavaScript, Python and Kotlin all work this way. It is what makes callbacks and higher-order functions possible.

## Example

A button takes a function to run when clicked. Lucy passes in her save function, and the button calls it later.

## Example code

```python
def shout(text):
    return text.upper()

say = shout
print(say("hi"))
# HI
```

The function is stored in a new name, then called through it.

## Why it matters

It lets you pass actions around like data. Sort rules, click handlers and retries all rely on it.

## Common mistake

Adding brackets when passing a function, like save(). That runs it at once and passes its answer instead.

## Three principles

- **Store it.** Put a function in a variable.
- **Pass it.** Give it to another function.
- **Return it.** A function can make one.

## Related terms

- [Function](https://learn.benibix.com/term/development/function)
- [Higher-Order Function](https://learn.benibix.com/term/development/higher-order-function)
- [Callback Function](https://learn.benibix.com/term/development/callback)
- [Lambda Function](https://learn.benibix.com/term/development/lambda)
- [Closure](https://learn.benibix.com/term/development/closure)
- [Functional Programming](https://learn.benibix.com/term/development/functional-programming)

## Told apart from

- [First-Class Function vs Higher-Order Function](https://learn.benibix.com/compare/first-class-function-vs-higher-order-function): With first-class functions, a function is a value you can store and pass. A higher-order function is one that takes in or hands back a function.

![A function named shout sits in the middle. Three arrows lead out of it. One puts it in a variable named say. One passes it into another function, apply. One shows a function make_greeter handing back a new function as its answer.](https://learn.benibix.com/diagrams/dev7-first-class-function.svg)

---

Source: https://learn.benibix.com/term/development/first-class-function
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
