Skip to content

Why the output of this code is '0,1,2,3,4,5' #35861

Closed Answered by devsnek
pikadun asked this question in General
Discussion options

You must be logged in to vote

I patched https://engine262.js.org to print when a function is pushed to the microtask queue, and when the resolve function from a promise constructor is called, by which i mean new Promise((resolve) => { resolve(5) }), not Promise.resolve(5).

Promise.resolve('p0')
  .then(function h0() {
    console.log(0);
    return Promise.resolve(4);
  })
  .then(function h1(r) {
    console.log(r);
    return 'h2ret';
  });

Promise.resolve('p1')
  .then(function h2() {
    console.log(1);
    return 'h2ret';
  })
  .then(function h3() {
    console.log(2);
    return 'h3ret';
  })
  .then(function h4() {
    console.log(3);
    return 'h4ret';
  })
  .then(function h5() {
    console.log(5);
    re…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by pikadun
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants