---
title: "Discussion on \"Task Queue and Job Queue - Deep dive into Javascript Event Loop Model\" | Hashnode"
description: "Discussion on \"Task Queue and Job Queue - Deep dive into Javascript Event Loop Model\". There is a famous saying, \n\nKeep every promise you make and only make promises you can keep.\n\nIn  my last post, I also made a promise that I shall write about the concept of Task and Job Queues. Here is the post on it. Interestingly, this post is mos..."
url: "https://hashnode.com/posts/task-queue-and-job-queue-deep-dive-into-javascript-event-loop-model/5cb431d905431a14119e1777"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Task Queue and Job Queue - Deep dive into Javascript Event Loop Model](https://blog.greenroots.info/task-queue-and-job-queue-deep-dive-into-javascript-event-loop-model?utm_source=hashnode&utm_medium=feed)

There is a famous saying, Keep every promise you make and only make promises you can keep. In my last post, I also made a promise that I shall write about the concept of Task and Job Queues. Here is the post on it. Interestingly, this post is mos...

Apr 15, 2019 · 4 min read · blog.greenroots.info  
Updated Jan 10, 2022  
Read the article

-   [#javascript](https://hashnode.com/tag/javascript)
-   [#programming-languages](https://hashnode.com/tag/programming-languages)
-   [#js](https://hashnode.com/tag/js)
-   [#event-loop](https://hashnode.com/tag/event-loop)
-   [#javascript-internals](https://hashnode.com/tag/javascript-internals)

## Written by

[Tapas Adhikary](https://hashnode.com/@atapas)

@atapas · Bangalore

  
[View profile](https://hashnode.com/@atapas)

Educator @tapaScript | Founder CreoWis & ReactPlay - Writer - YouTuber - Open Source

Co-Founder, @CreoWis | Teacher, @tapaScript | Founder, @ReactPlay | YouTuber | Writer | Human

## Responses 6

Markdown supported · ⌘↵ to post

[Wessam Abdelnabi](https://hashnode.com/@wessam18)

[Jun 6, 2024](https://hashnode.com/posts/task-queue-and-job-queue-deep-dive-into-javascript-event-loop-model/5cb431d905431a14119e1777/comment/6660fc580407079ac4cdf325)

it is very very useful thanks alot

[Brian Coverstone](https://hashnode.com/@Brain2000)

[Jan 7, 2022](https://hashnode.com/posts/task-queue-and-job-queue-deep-dive-into-javascript-event-loop-model/5cb431d905431a14119e1777/comment/61d87d528d56921d07b91440)

> MacroTasks are called, Tasks and MicroTasks are called Jobs.

This ruined me for about an hour until I realized the comma was in the wrong place

[Tapas Adhikary](https://hashnode.com/@atapas)

[Jan 10, 2022](https://hashnode.com/posts/task-queue-and-job-queue-deep-dive-into-javascript-event-loop-model/5cb431d905431a14119e1777/comment/61d87d528d56921d07b91440#reply-61dc6089cda0d0294b69bc40)

Thanks for reporting this. Corrected.

[xy Zing](https://hashnode.com/@zing)

[Dec 24, 2021](https://hashnode.com/posts/task-queue-and-job-queue-deep-dive-into-javascript-event-loop-model/5cb431d905431a14119e1777/comment/61c57871ca80154c1f675302)

Nice post for beginner. Thank you!

[Adrian Belen](https://hashnode.com/@stepOniichan)

[Jun 15, 2021](https://hashnode.com/posts/task-queue-and-job-queue-deep-dive-into-javascript-event-loop-model/5cb431d905431a14119e1777/comment/60c81639590a5c0656565600)

Can you please explain this me why the event loop prioritize cartoon's setTimeouts than the then's setTimeout? Ok, I did some changes here

```
const tom = () => console.log('Tom');
const jerry = () => console.log('Jerry');
const doggy = () => console.log('Doggy');

const cartoon = () => {
  console.log('Cartoon');

  setTimeout(tom, 0);
  setTimeout(doggy, 0);

  new Promise((resolve, reject) =>{
      resolve('I am a Promise, right after tom and doggy! Really?');
    setTimeout(()=>{console.log('inner timeout')},0)
  }
  ).then(resolve => console.log(resolve));
  new Promise((resolve, reject) =>
    resolve('I am a Promise after Promise!')
  ).then(resolve => console.log(resolve));

  jerry();
}

cartoon();
```

"Cartoon"

"Jerry"

"I am a Promise, right after tom and doggy! Really?"

"I am a Promise after Promise!"

"Tom"

"Doggy"

"inner timeout"

[Jalaj Gupta](https://hashnode.com/@jalaj)

[Jun 27, 2021](https://hashnode.com/posts/task-queue-and-job-queue-deep-dive-into-javascript-event-loop-model/5cb431d905431a14119e1777/comment/60c81639590a5c0656565600#reply-60d8943dcb0aa8118c23cdaf)

I think it doesn't matter if the setTimeout is inside `then`, because it will still get added to the TASK queue and since all the timers are 0, they will get executed in order they got en-queued. `tom -> doggy -> inner timeout`

[Tapas Adhikary](https://hashnode.com/@atapas)

[Aug 25, 2021](https://hashnode.com/posts/task-queue-and-job-queue-deep-dive-into-javascript-event-loop-model/5cb431d905431a14119e1777/comment/60c81639590a5c0656565600#reply-61260b1ab115357df05f5990)

[Jalaj Gupta](https://hashnode.com/@jalaj) , That's absoloutely correct.

[Izzatullo Kanoatov](https://hashnode.com/@uzbek)

[Jan 31, 2021](https://hashnode.com/posts/task-queue-and-job-queue-deep-dive-into-javascript-event-loop-model/5cb431d905431a14119e1777/comment/60169ba5e54673573b572c12)

Thank you very much. Very detailed and mind blowing explanation. Understood. )

[Tapas Adhikary](https://hashnode.com/@atapas)

[Jan 31, 2021](https://hashnode.com/posts/task-queue-and-job-queue-deep-dive-into-javascript-event-loop-model/5cb431d905431a14119e1777/comment/60169ba5e54673573b572c12#reply-60169e08e54673573b572c3f)

Thank you! Glad it was helpful 😍

[Thamaraiselvam](https://hashnode.com/@thamaraiselvam)

[Apr 15, 2019](https://hashnode.com/posts/task-queue-and-job-queue-deep-dive-into-javascript-event-loop-model/5cb431d905431a14119e1777/comment/5cb464fb05431a14119e1935)

Thanks for great Article.

Cartoon

Jerry

//These micro task has precedence over macro tasks

I am a Promise, right after tom and doggy! Really?

I am a Promise after Promise!

//Finally macro tasks

Doggy

Tom

[Vedamruta Udavant](https://hashnode.com/@vedamruta)

[Jul 27, 2023](https://hashnode.com/posts/task-queue-and-job-queue-deep-dive-into-javascript-event-loop-model/5cb431d905431a14119e1777/comment/5cb464fb05431a14119e1935#reply-64c2d014513c1c494e44eecf)

[Tapas Adhikary](https://hashnode.com/@atapas) I didn't understood the 11th point in the above explanation. setTimeout(tom, 50); setTimeout(doggy, 30); The task queue is filled this way: \[tom(), doggy()\] So why isn't the output this because task queue is a task so FIFO no matter the timeout duration: Cartoon Jerry I am a Promise, right after tom and doggy! Really? I am a Promise after Promise! Tom Doggy

[Tapas Adhikary](https://hashnode.com/@atapas)

[Jul 28, 2023](https://hashnode.com/posts/task-queue-and-job-queue-deep-dive-into-javascript-event-loop-model/5cb431d905431a14119e1777/comment/5cb464fb05431a14119e1935#reply-64c38e63f5fc5651f9e85e4c)

[Vedamruta Udavant](https://hashnode.com/@vedamruta) No for setTimeout, setInterval kind of web APIs it will be filled based on the delayed time. That's the catch you need to keep in mind. So it will \[doggy(), tom()\] this way.

[Vedamruta Udavant](https://hashnode.com/@vedamruta)

[Jul 28, 2023](https://hashnode.com/posts/task-queue-and-job-queue-deep-dive-into-javascript-event-loop-model/5cb431d905431a14119e1777/comment/5cb464fb05431a14119e1935#reply-64c3a1acf5fc5651f9e86211)

[Tapas Adhikary](https://hashnode.com/@atapas) Got it, thank you 😄
