0
Promise.resolve("1")
  .then((res) => {
    console.log(res);
  })
  .finally(() => {
    console.log("finally");
  });
Promise.resolve("2").finally(() => {
  console.log("finally2");
});

Here is the output:


1 
finally2 
finally 

Could anyone please explain why the finally2 is printed before finally?

Sean Liu
  • 441
  • 3
  • 13
  • To elaborate on the duplicate, your first `finally()` is attached to the promise returned by `.then()`, thus you have two microtasks scheduled in a chain. The second `finally()` is attached to the original promise, there is only one queued microtask – Phil Jan 31 '22 at 01:42

0 Answers0