What exactly is the Event Loop in JavaScript? | CodeSketched

Поделиться
HTML-код
  • Опубликовано: 30 июн 2024
  • In this video, we look at the concept of the event loop. We learn about the heap, the stack, and the message queue and how these three concepts work together which is at the core of how the language works.
    Check out our other popular videos:
    1. Learn about public-key cryptography
    • encryption explained |...
    2. maximum substring in a string (Google interview question)
    • Google Interview Quest...
    3. How the javascript engine works?
    • How the Javascript eng...
    4. Real time median in a stream, another google interview question
    • Median in a stream | p...
    5. Understand the Javascript event loop
    • Javascript event loop ...
    6. Understand Promises in javascript
    • JavaScript promises | ...
    7. Git basics you must know
    • Git basics | 8 command...

Комментарии • 8

  • @Shivam-sl4sp
    @Shivam-sl4sp 9 месяцев назад +3

    Remarkable efforts and unbelievably effective and concise. Keep making these behind the scences in depth videos very few people cover these and less than a handful can deliver it effectively.

    • @CodeSketched
      @CodeSketched  9 месяцев назад

      Thanks a lot for the kind words :)

  • @shashankbhatgs1150
    @shashankbhatgs1150 2 года назад +2

    Great explanation!
    And about the question, I think the setTimeout with 0 sec would still wait in the queue till the other functions get executed.

  • @this.channel
    @this.channel 2 года назад

    Perhaps setTimeout with 0 passed is a way to do non blocking code. Like async or something.

  • @shivamrawat7523
    @shivamrawat7523 Год назад

    does every function has it's own personal message queue? what if there's async code within async code? will it go to queue or stack?

    • @Shivam-sl4sp
      @Shivam-sl4sp 9 месяцев назад

      There is a single Message Queue (Task Queue) in JavaScript for handling asynchronous operations. This queue includes tasks related to DOM events (e.g., click events) and network requests (e.g., HTTP requests). Within the Message Queue, there are two different types of tasks: the Callback Queue (for functions like setTimeout callbacks) and the Microtask Queue (for high-priority tasks like promises and certain DOM-related tasks). The Microtask Queue has a higher priority than the Callback Queue, and the event loop first serves the Microtask Queue before moving to the Callback Queue. This ensures that tasks in the Microtask Queue are executed immediately and in order, while tasks in the Callback Queue are processed when the call stack is empty. Promises and network requests typically go to the Microtask Queue due to their high-priority nature.

  • @pavankumar-of4ew
    @pavankumar-of4ew 2 месяца назад

    to avoid that ,async concept we need to use