JavaScript

JavaScript Promises and Async/Await: As Fast As Possible™

Using promises, we can write asynchronous programs in a more manageable way. Using Async/Await syntax, a promise-based asynchronous code can be written in a synchronous format which saves a lot of time and code becomes scalable.

Uday Hiwarale
JsPoint
Published in
17 min readJul 26, 2019

--

(source: pexels.com)

JavaScript executes code in a single thread, which makes it blocking. Let’s take a simple example of calling three functions in series.

As we can see from the above result, each function call and console.log statement is executing in series AKA in a synchronous manner. This means until the function a has returned, the next line of code won’t be called. By default, a function with no return statement returns undefined value.

Using Web APIs, some JavaScript jobs can be transferred to other threads. For example, handling of AJAX request should be done on a different thread, else our main thread would be blocked until the network response is received. This would be a horrible UX for the user, as his/her screen would…

--

--