0

What is the difference between Event Loop and Callback function in node.js?

0

1 Answer 1

2

Event Loop is in the underlying system that execute your program. Every time your code needs to access an external resource (for example a XHR call to an api) you usually do something like that:

callToTheApi('/api/some/url', function(response) { ... the callback code ...}

The runtime execute the call and pass the callback function (second parameter of the callToTheApi function) to the Event Queue. This means 'Execute the call to the api and when the api has done please tell me and go on with the call back'. The event loop while the api are doing their job put in execution some other piece of code and resume the callback once the api has done.

You can find a good explanation here: Understanding the Node.js Event Loop

Sign up to request clarification or add additional context in comments.

1 Comment

You are welcome! Could you set it as the "answer" :) Thankyou.

Your Answer

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.