"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > Higher order function in java script

Higher order function in java script

Published on 2024-11-01
Browse:868

Higher order function in java script

Defination

*Any function which is taking another function as a argument that function is called HOF.
*Function are called HOF only if it takes minimum one function as a argument.
*Array.map, Array.filter, and Array.reduce are common higher-order functions that take a callback function as an argument.

syntax:

function myfunction(name,city){



}
myfunction(function(){},function(){});

Example

function fun(callback1, callback2) {
callback1();
callback2();
}

// Example functions to pass as arguments
function sayHello() {
console.log('Hello!');
}

function sayGoodbye() {
console.log('Goodbye!');
}

// Calling 'fun' with two functions as arguments
fun(sayHello, sayGoodbye);

// Output:
// Hello!
// Goodbye!

Not a Higher order function

function f1(x){
--------------------
}
f1(100);
*Because it does not take function as a argument.

Release Statement This article is reproduced at: https://dev.to/t_shivakumar_0dc86c6486c/higher-order-function-in-java-script-21e5?1 If there is any infringement, please contact [email protected] to delete it
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3