Skip to main content

Command Palette

Search for a command to run...

First class function in javascript

Higher Order Functions, callback function, returning a function in javascript

Updated
1 min read
A

I am working as freelancer. I am a experienced full stack web developer. My lovely stack is MERN but I am open for new tech. I love to work with teammates for achieve goals. I love researches to find specific new things.

What is First-class-function?

In javascript, A function can be called a first-class-function, if

  1. It is passing as an argument in another function

  2. It returns as a return value.

  3. It is treated as a variable value.

Examples of First class Function

  1. Passing as an argument

Here we pass powerTwo in the Powercube function.

  1. Assigning function as a variable value

  1. Returning a function

Higher-order-function

A function which passes another function as an argument or returns a function is called a higher-order function.

In the above examples welcomemessege() and Powercube() are higher-order functions.

Callback function

When a function passes as an argument in any function, is called a callback function.

In the above examples, powerTwo() is a callback function.