Understanding Asynchronous Programming in JavaScript

setTimeout(()=>{ console.log(‘Hello’); }, 3000);
The JavaScript runtime environment with Web APIs, Callback queue and Event Loop.
  1. Calls are loaded onto the Call Stack in V8 engine
  2. Anything that relates to ajax/xhr calls, DOM events and timing is accomplished with the help of Web APIs supplied by the browser
  3. Anything that returns as a callback, and from the execution of using those Web APIs, is added on the Callback Queue
  4. A mysterious — ever-so-notorious — Event Loop pushes these callbacks from Callback Queue to the Call Stack where they are executed
setTimeout(()=>{ console.log(‘Hello’); }, 0); //instant execution??

--

--

--

Co-Founder of <indvideotech> community for Video Engineers in India. Solution Architect, Full-Stack Developer, Ad Insertion Evangelist, and Think Tank.

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

Recommended from Medium

A front end beginner’s guide to linking

Building a SaaS from scratch using Django and Vue.js

Building a Node.js API with TypeScript and GraphQL

Structuring React Components for Easy Imports

HOW TO REACTJS OR ANY WEB SITE HOST IN HEROKU with GIT-HUB REPOSITORY?

Angular forms : a quick simple exaplanation

Launching the Front-End Tooling Survey 2019

Using Formik To Build Dynamic Forms In React — Faster & Better

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
Sanjeev Pandey

Sanjeev Pandey

Co-Founder of <indvideotech> community for Video Engineers in India. Solution Architect, Full-Stack Developer, Ad Insertion Evangelist, and Think Tank.

More from Medium

Finding the most and least frequent elements in JavaScript

Mistakes per day in JS

All You Need to Know About setTimeout in Javascript

How to Fix JavaScript Runtime issues — Lazy Loading