
The function that accepts other functions as a parameter:
Let's look into an example that illustrates how a function accepts other functions as a parameter:
xxxxxxxxxx
12
const names= ['John', 'Tina','Kale','Max']
function useFunction(arr,function_as_argument){
for(let i=0; i<arr.length; i++){
function_as_argument(arr[i]);
}
}
function function_as_argument(name){
console.log("Hello " + name );
}
useFunction(names,function_as_argument);
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment