The JavaScript event loop - Deepstash

The JavaScript event loop

Otherwise, here’s a quick step-by-step explanation of how the JavaScript Event Loop works. 

  • Push main() onto the call stack. 
  • Push console.log onto the call stack. This then runs right away and gets popped. 
  • Push Settimeout onto the stack. Settimeout is a Node API.
  • After registering it in the APIs, setTimeout gets popped from the call stack. 
  • Now the second setTimeout gets registered in the same way. We now have two Node APIs waiting to execute. 
  • After waiting for 0 seconds, setTimeout gets moved to the callback queue, and the same thing happens with setTimeout . 
  • Only one statement can execute at a time. This is taken care of by the event loop.

7

74 reads

CURATED FROM

IDEAS CURATED BY

apron

Recruitment consultant

The idea is part of this collection:

Introduction to Web 3.0

Learn more about product with this collection

The differences between Web 2.0 and Web 3.0

The future of the internet

Understanding the potential of Web 3.0

Related collections

Read & Learn

20x Faster

without
deepstash

with
deepstash

with

deepstash

Personalized microlearning

100+ Learning Journeys

Access to 200,000+ ideas

Access to the mobile app

Unlimited idea saving

Unlimited history

Unlimited listening to ideas

Downloading & offline access

Supercharge your mind with one idea per day

Enter your email and spend 1 minute every day to learn something new.

Email

I agree to receive email updates