0

This first guarantee by MDN does not make sense to me. Can someone explain it using code?

MDN 3 Guarantees

Callbacks will never be called before the completion of the current run of the JavaScript event loop.

  • What have you tried so far? – joshuakcockrell May 14 '19 at 20:55
  • 1
    Do you not understand what it means in general, or are you looking for reasons why it is a good thing? – melpomene May 14 '19 at 20:55
  • 2
    I would advise having a read of [this](https://oren.github.io/blog/zalgo.html), amongst several other similar articles online. (Disclaimer: I only just dragged this out of a google search, it was the simplest explanation I could find in a few minutes, but there are probably better ones.) The point of the guarantee you quote is that Promises guarantee that the callback will actually be executed asynchronously, whatever happens - therefore you can never "release Zalgo". – Robin Zigmond May 14 '19 at 21:01

1 Answers1

4
  Promise.resolve(2).then(console.log);
  console.log(1);

Will always log 1, then 2.

You can resolve the promise now, somewhen or never. But the .then callbacks will always run after the synchronous code finished.

Jonas Wilms
  • 132,000
  • 20
  • 149
  • 151