0

I wanted to create a function where in that i am passing a call back function that callback function should be run later after my other task is done like this

console.log(1);
console.log(2);
const asyncfunc = (callback) => {
    callback();
};

asyncfunc(() => {
 let i = 1;
 while (i < 1000) {
    console.log(i);
    i++;
  }
});
console.log(3);
console.log(4);

I am expecting an output like this : 1 2 3 4 1 2 3 . . . . 1000

But these last two console logs are running after the callback function

yes_vikash
  • 61
  • 3

0 Answers0