DEV Community

Ramesh Vishnoi
Ramesh Vishnoi

Posted on • Edited on

6

High Order Function Explained

One of the commonly asked question for Frontend Interview. This question is valid from Junior role to Lead role. Your answer determine if you have JS basics clear or not.

What is High Order Function ?

By Definition - A Function which accepts a function as argument or returns a function as value or Both.

Most of the candidates answers half correctly. In order to qualify a function as High Order Function it has to pass one of the 3 criteria -

  1. Accept a function as a argument
  2. Return a function as a value
  3. Both of the above

Example of 1st Criteria :

Example of High order Function accepting function as argument

Here getUser function accepts onSuccess and onError. These are functions as argument. In this example, getUser does not return anything.

Example of 2nd Criteria :

Example of High order Function returning function as value

Here getSumFunc returns a new function as value.

Example of 3rd Criteria :

Example of High order Function accepting function as argument and returning function as value

Here getConfidentialFunction is a funtion which converts a normal function into a function with access to confidential data. Here getConfidentialFunction accepts a fucntion as argument but also returns a new function.

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More