1

I have two log then I want first log(2) and then run log(1)

console.lo(1);
console.log(2);

END == > 2,1 in log

3 Answers3

2

You should use promise and learn about it;

 setTimeout(async () => {
       console.log(1)
      }, 100);
       console.log(2)
1

JavaScript works from top to bottom, the easiest way to achieve what you are looking for is to change the positions

console.lo(2); console.log(1);

0

You can simply use setTimeout and run the callback function after a certain interval of time.

You should also see Why is setTimeout(fn, 0) sometimes useful?

setTimeout(_ => console.log(1), 0);
console.log(2);
DecPK
  • 24,537
  • 6
  • 26
  • 42