JavaScript microtask quiz

แชร์
ฝัง
  • เผยแพร่เมื่อ 12 ก.พ. 2018
  • I asked a question on Twitter ( / 963007466471677953 , this is the answer, and reasons why.
  • เกม

ความคิดเห็น • 14

  • @saadabbasi2063
    @saadabbasi2063 5 ปีที่แล้ว +2

    Thanks Jake, its really helping me to solidify my content for a local JavaScript Meetup here in Pakistan 🇵🇰.

  • @user-ie7md3mm6x
    @user-ie7md3mm6x 2 ปีที่แล้ว

    That helped me alot to think about execution order of microtasks properly! Big thanks to you man!

  • @ra-dro
    @ra-dro 4 ปีที่แล้ว

    Amazing sense of humor.

  • @gnclmorais
    @gnclmorais 6 ปีที่แล้ว

    Thank you for looking into this!

  • @omergronich778
    @omergronich778 4 ปีที่แล้ว

    Brilliant. Thank you.

  • @Brianle180
    @Brianle180 4 ปีที่แล้ว

    Thanks Jake. In a nutshell, it bases on .then order.

  • @rthangam77
    @rthangam77 6 ปีที่แล้ว

    Nice

  • @sadiqabdullah138
    @sadiqabdullah138 9 หลายเดือนก่อน

    Oh, your video cleared my misconception about microtask queueing ... But in your second example at 3:22 , where the outer promise .then() is called. You said that since it's not resolved, it won't be added to the microtask queue. Can you tell me where it would go then

  • @davesmith701
    @davesmith701 5 ปีที่แล้ว

    That was too funny when you got annoyed at those posting up the answers ..... (for the record, Im not one of them)

  • @mohsen--karimi
    @mohsen--karimi 6 ปีที่แล้ว

    new Promise((resolve,reject) => {
    Promise.resolve().then(() => {
    setTimeout(function(){
    resolve(1);
    Promise.resolve().then(()=> console.log(2));
    },0);
    })
    }).then((t) => console.log(t));
    console.log(3);
    Q: Executor promise callback wait for task(setTimeout) ?

    • @jakearchibald
      @jakearchibald  6 ปีที่แล้ว +2

      I gave a talk recently where I look at the interaction of tasks, rendering, and microtasks. th-cam.com/video/cCOL7MC4Pl0/w-d-xo.html.
      For this particular case the answer is 3, 1, 2. 3 is logged synchronously, a microtask is queued for the promise inside the executor, and that callback queues a task. When the task is run, resolve is called, queueing the microtask that logs 1, then a microtask is called for the callback that logs 2.

    • @mohsen--karimi
      @mohsen--karimi 6 ปีที่แล้ว

      Thanks.

    • @davesmith701
      @davesmith701 5 ปีที่แล้ว

      @@jakearchibald Loving your work Mr Archibald ... your comedy could do with a bit of work, but other that, its all good.

  • @ThadHumphries
    @ThadHumphries 6 ปีที่แล้ว

    Also see th-cam.com/video/cCOL7MC4Pl0/w-d-xo.html