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 -
- Accept a function as a argument
- Return a function as a value
- Both of the above
Example of 1st Criteria :
Here getUser
function accepts onSuccess
and onError
. These are functions as argument. In this example, getUser
does not return anything.
Example of 2nd Criteria :
Here getSumFunc
returns a new function as value.
Example of 3rd Criteria :
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.
Top comments (0)