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?

asked Apr 7, 2019 at 12:04
1
  • do you need any more help with this question? Please let me know or mark my answer as accepted. Thank you. Commented Jul 23, 2019 at 15:23

1 Answer 1

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.

answered May 24, 2019 at 15:17

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.