Functions in JavaScript
Title
Question
Hello Folks,
Can anyone tell me what are higher-order functions in JavaScript, as I started learning javascript, please let me know your suggestions to bridge the gap.
Can anyone tell me what are higher-order functions in JavaScript, as I started learning javascript, please let me know your suggestions to bridge the gap.
Thanks in advance!
JavaScript Functions-in-JS 02-03 min 20-30 sec
Answers:
A Higher-order function is a function that takes a function as an input parameter and returns the modified function.
The name of the function which is taking a function as param is HOF.
// Higher-order function example (function as an argument)
function operateOnNumber(number, operation) {
return operation(number);
}
function square(x) {
return x * x;
}
function double(x) {
return x * 2;
}
console.log(operateOnNumber(5, square)); // Output: 25
console.log(operateOnNumber(3, double)); // Output: 6
Login to add comment