...

/

Asynchronicity in JavaScript

Asynchronicity in JavaScript

Understanding asynchronicity in JavaScript along with event loop and callback queue

We'll cover the following...

Background

JavaScript supports asynchronous programming. However, writing asynchronous programs is tricky if you don’t have knowledge of the blocking code and JavaScript. Let’s dive deeper into how asynchronicity is engineered in the language.

Callback functions

To leverage asynchronous functions in JavaScript, design callback functions. Callback functions are invoked as soon as the blocking function finishes. Let’s revisit an example.

Press + to interact
function complete(){
console.log("function completed!");
return;
}
setTimeout(complete, 2000.0); // 2000 = 2 seconds of idle time

Above, the complete function acts as the callback function for setTimeout function ...