use of callback function
//there are some case where the output wont be present
//in this case y value will be undefined
function add(a,b){
setTimeout(()=>{
return a+b;
},2000)
}
let y=add(2,3)
console.log(y)
console.log("done")
//thus to prevent this error we use call back function
// still result is seen but after execution of other code
function wow(a,b){
console.log(a+b)
}
function add(a,b,wow){
setTimeout(()=>{
wow(a,b)
},2000)
}
add(2,3,wow)
console.log("done")
Comments
Post a Comment