1

I'm learning about javascript's event loop, however I'm not understanding what a message is? The resources I find mention how the callback associated with events get added to the message queue, but nothing seems to explain what a message actually is. I'm assuming its different then the callback itself. What is the message, what does the message do, why not just pass the callback to the queue itself, why does it need an associated message?

1

JavaScript is built on an event-based programming model which consists of two core ideas:

  • callback functions: a function passed to another function which initiates an activity. Please look on this MDN link for examples.

  • processing loop: Also known as a message loop or event loop, this continuously takes the highest priority message/event on the queue and calls the associated callback function that was registered earlier to handle the event/message.

This processing loop may receive messages/events sent from:

  • native system I/O calls to handle things like reading from the local file system
  • events generated in a web browser from a user clicking an HTML element on a web site.

We can go deeper into a discussion of the tradeoffs associated with this type of system, however, I believe that is a separate conversation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.