DEV Community

Cover image for Event Loops in Javascript
Shubham Tiwari
Shubham Tiwari

Posted on

Event Loops in Javascript

Hello guys today i want to discuss the topic "Event Loop" in Javascript.
Lets get started...

What is Event Loop?

  • Javascript is a single threaded language so , it performs one operation at a time.The language doesn't support multithreading
  • Event Loops helps Javascript to perform asynchronous operations.

Call Stack -

  • Call stack is used to keep track of all the operations to be executing and once the operation is executed it is pop out from the call stack and the next operation in line will be executed.

Event Queue -

  • Event Queue is used to to push new function to the call stack to execute it. It follows the queue pattern of FIFO(First in First out).It sends the functions in the exact sequence they are in.

Browser Api -

  • These are built-in Api's in Browsers
  • It helps in performing the Aysnc operation by creating a seperate thread and once the operation is ready to be executed it is sent to the event queue.
  • The Event queue wait until the call stack is empty then push this aysnc operation to the call stack to get executed.
  • An example of this is "settimeout" in js.

Image description

Thats it for this post.
THANK YOU FOR READING THIS POST AND IF YOU FIND ANY MISTAKE OR WANTS TO GIVE ANY SUGGESTION FOR IMPROVEMENT, PLEASE MENTION IT IN THE COMMENT SECTION.
^^You can help me by some donation at the link below Thank you👇👇 ^^
☕ --> https://www.buymeacoffee.com/waaduheck <--

Also check these posts as well
https://dev.to/shubhamtiwari909/javascript-map-with-filter-2jgo

https://dev.to/shubhamtiwari909/e-quotes-3bng

https://dev.to/shubhamtiwari909/deploy-react-app-on-netlify-kl

Top comments (0)