Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • Theoretically, the img.onload or img.onerror events could be raised before the Promise is constructed so the promise would not resolve, couldn't it? Commented Feb 20 at 13:57
  • I'm pretty sure the event loop won't tick until the function starts awaiting, which happens when the promise constructor's callback returns Commented Feb 20 at 23:39
  • @MartinSchneider looking back, it would probably be wiser to assign img.src inside the promise constructor callback, after assigning img.onerror Commented Sep 30 at 18:55
  • Or moving the img.src assignment after the promise construction and awaiting it just after, instead of when constructed :) Commented Oct 1 at 7:48