Higher Order & Call Back Functions Notes
Higher Order & Call Back Functions Notes
function first(fun) {
fun()
In the above code we are passing function second as input to function first when
calling,(fun& second both are same functions) so first is higher order function & second is callback
function which will be executed inside that higher order function at some point of time like after
completion of some task or any event occurs when event binding is done as below.
@csworldtelugu
h1.addEventListener('click' ,showpopup)
function showpopup() {
//code
}
function wish(txt) {
In the above function, an arrow function is returned from wish function which we can call later to
wish any person. Initially to wish() passing some text, in the return function we are fixing that text,
but later we can call that function just to wish any person with their name as input. In the below
same wish function is calling with good afternoon now wish function return a function with text
as good afternoon fix.
@csworldtelugu
Another Example of higher order & callback function
function twice(num) {
console.log(num + ":" + (num + num))
}
function cube(num) {
console.log(num + ":" + (num * num * num))
}
function square(num) {
console.log(num + ":" + (num * num))
}
console.log("twice")
arrayAnyOperation(arr, twice);
console.log("trice")
arrayAnyOperation(arr, trice);
@csworldtelugu
Frequently used higher order functions in JavaScript
• map()
• filter()
• reduce()
• sort()
• setTimeOut()
• setInterval()
• forEach()
@csworldtelugu