First class function in javascript

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

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.