1.

Explain callback functions in JavaScript?

Answer»

 A Higher Order Function is a function that TAKES one or more function as argument. We use them at many places in JavaScript, and are also called callback functions.

Consider, the below JS code which uses filter to filter-out Adult people. Here, we have a callback function isAdult  which is called on every item.

These callbacks are USUALLY DEFINED inline as anonymous function. So, the REFACTORED code is below.

 We can further refactor it using arrow functions as below.

So, the array METHODS of map(), filter(), reduce(), forEach() are all Higher Order Functions.

Beside this eventListener like below are also Higher Order Function, as they use a callback function.



Discussion

No Comment Found