settingsAccountsettings
By using our mini forum, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy
Menusettings

Q: Example of Higher Order Functions in JavaScript

+3 votes

Can you please give an example of an usage of Higher Order Functions in java script? Meaning showing a script as an example of passing function(s) to other function(s) in javascript.

 

thanks

asked in JavaScript category by user mitko

1 Answer

+2 votes

Here's one example:

//Higher Order Functions: passing function(s) to other functions

function sing() {
    console.log("twinkle twinkle...")
    console.log("how I wonder...")
}
setInterval(sing, 1000);//pass the function sing() as an argument + 1000 is a milliseconds
clearInterval(2);
setInterval(function () {
    console.log("I am an anonymous function");
    console.log("THIS IS AWESOME!");
}, 2000);//2000 milliseconds

 

answered by user nikole
...