The Event Loop in JavaScript

Call Stack:

A Simple Example:

const city = () => console.log("city");const state = () => console.log("state");
const country = () => { console.log("country"); state(); city();}country();
countrystatecity

The Message Queue:

const city = () => console.log("city");const state = () => console.log("state");
const country = () => { console.log("country"); setTimeout(state,0); city();}
country();
countrycitystate

The Job Queue (ES6):

const city = () => console.log("city");const state = () => console.log("state");
const country = () => { console.log("country"); setTimeout(state,0); new Promise((resolve, reject) => resolve("After city and before state") ).then(resolve => console.log(resolve)); city();}country();
countrycityAfter city and before statestate

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Steps to Include Custom CSS and JS Files in Ionic 3 — Zerone Consulting

Angular 4 Connect with PHP backend

Using React Hooks to Make API Calls

Class based counter example

How to generate a SHA-256 hash with JavaScript

React Native: How To Open App Settings Page

Considerations for writing React Components — Part 02: Function vs. Class components

Best Tools to Test and Document Your API like a Hero

Https + Express with Openssl

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Marcus Siegel

Marcus Siegel

More from Medium

The Awesome CSS Transform Property and Scale Function

What is the transform scaleX function

Target class controller does not exist — Laravel 8

Target class controller does not exist - Laravel 8

Health Collectable! -Updated!

Adobe Connected Assets