Higher order function in java script

王林
Release: 2024-08-17 20:31:32
Original
829 people have browsed it

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.

The above is the detailed content of Higher order function in java script. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!