11 KiB
| title | chunk | source | category | tags | date_saved | instance |
|---|---|---|---|---|---|---|
| First-class function - Glossary | MDN | 1/3 | https://developer.mozilla.org/en-US/docs/Glossary/First-class_Function | reference | web, html, css, javascript, documentation | 2026-05-05T05:31:30.661535+00:00 | kb-cron |
MDN HTML HTML: Markup language
HTML reference
HTML guides
Markup languages
CSS reference
CSS guides
Layout cookbook
JavaScriptJS JavaScript: Scripting language
JS reference
JS guides
Web APIs Web APIs: Programming interfaces
Web API reference
Web API guides
- Using the Web animation API
- Using the Fetch API
- Working with the History API
- Using the Web speech API
- Using web workers
Technologies
Topics
Learn Learn web development
Frontend developer course
- Getting started modules
- Core modules
- MDN Curriculum
- Check out the video course from Scrimba, our partner
Learn HTML
Learn CSS
Learn JavaScript
Tools Discover our tools
About Get to know MDN better
First-class function
A programming language is said to have First-class functions when functions in that language are treated like any other variable. For example, in such a language, a function can be passed as an argument to other functions, can be returned by another function and can be assigned as a value to a variable.
In this article
Examples
Assigning a function to a variable
We assigned an Anonymous Function to a Variable, then we used that variable to invoke the function by adding parentheses () at the end.
Note: Even if your function was named, you can use the variable name to invoke it. Naming it will be helpful when debugging your code. But it won't affect the way we invoke it.
Passing a function as an argument
We are passing our sayHello() function as an argument to the greeting() function, this explains how we are treating the function as a value.
Note: The function that we pass as an argument to another function is called a callback function. sayHello()is a callback function.
Returning a function
In this example, we are returning a function from another function - We can return a function because functions in JavaScript are treated as values. Note: A function that returns a function or takes other functions as arguments is called a higher-order function.
See also
- First-class functions on Wikipedia
- Related glossary terms: