function one(){
console.log(1);
}
function two(callback){
setTimeout(()=>{
console.log(2);
},2000);
callback();
}
two(one);
While I am running this code, 1 is displaying first and then 2 because 2 is taking 2 second time to display. Suppose if there is an api instead of console.log(2) in function two which is taking 2 second to respond, so How I can call function one after completion of function two using callback(); which I can do in this case if I use callback() inside setTimeout function but what if there is an api where I am not using setTimeout and it's taking 2-3 second?
async-await, so that 2nd function will be called after api call is completed :)second functionfirst withasyncand then call thefirst functionon completingsecond. Simple. Bro think simple it will resolve all questions