What are First-class Functions?

What are First-class Functions?

Ferenc Almasi β€’ 2020 November 12 β€’ Read time 1 min read
  • twitter
  • facebook
JavaScript

In JavaScript and other functional languages, functions can also be assigned to variables and you can pass them around, just like they were variables.

First-class function are functions that you can:

  • Pass as arguments to other functions
  • Store them in a variable
  • Return as values from other functions

Take the following as an example:

Copied to clipboard! Playground
const greet = function () {
    console.log('πŸ‘‹');
}

// The greet variable is now a function, we can invoke it
greet();
first-class.js

Here the greet function is passed around and is treated like a variable.

What are first-class functions in JavaScript?
If you would like to see more Webtips, follow @flowforfrank

Why Do You Need to Know About Functional Programming?

Resources:

  • twitter
  • facebook
JavaScript
Did you find this page helpful?
πŸ“š More Webtips
Mentoring

Rocket Launch Your Career

Speed up your learning progress with our mentorship program. Join as a mentee to unlock the full potential of Webtips and get a personalized learning experience by experts to master the following frontend technologies:

Courses

Recommended

This site uses cookies We use cookies to understand visitors and create a better experience for you. By clicking on "Accept", you accept its use. To find out more, please see our privacy policy.