You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//call back function with passing function as formal argument
functionsayHello(){
return"Hello, ";
}
functionintro(helloMessage,name){
console.log(helloMessage()+name);
}
intro(sayHello,"JavaScript!");
console.log("------------5-------------");
//call back function with passing function as formal argument
functiongreet(wish){
console.log(`${wish()}, Welcome to the JavaScript Course`);
}
functiongoodMorning(){
return"Good Morning!";
}
greet(goodMorning);
console.log("------------6-------------");
//call back function with passing function as formal argument with IIFE
functionwish(message){
returnfunction(wishes){
console.log(`${wishes}, ${message}`);
};
}
wish("Welcome to the session")("Hi");//execute based on IIFE
console.log("------------6-------------");
//The arrow function implicitly returns if there is a single line of code, but if you enclose the code within curly brackets, it will not return implicitly.
varprod=(n1,n2)=>n1*n2;
varval=prod(5,2);
console.log(val);
console.log("------------7-------------");
// create variable as function
constdisplay=(str)=>{
console.log(str);
};
display("display function variable");
console.log("------------8-------------");
/* First-class Function : A programming language is said to have First-class functions when functions in that language are treated like any other variable. Means You can assign function to variable, function can be pass as formal argument to other function and also you can return function . For example, in such a language, a function can be passed as an argument to other functions, can be returned by another function and can be assigned as a value to a variable. */