0 votes
in C Plus Plus by
Can you show an example of a function with a return statement in a higher-order function?

1 Answer

0 votes
by

Yes, a higher-order function is one that can accept other functions as arguments and/or return them as results. Here’s an example in JavaScript:

function higherOrderFunction(num) {
return function addFive() {
return num + 5;
}
}
let result = higherOrderFunction(10);
console.log(result()); // Outputs: 15

In this code, 

higherOrderFunction

 is the higher-order function because it returns another function (

addFive

). The inner function uses a return statement to give back the result of adding five to whatever number was passed into the outer function.

...