DEV Community

Cover image for β­οΈπŸŽ€ JavaScript Visualized: Promises & Async/Await

β­οΈπŸŽ€ JavaScript Visualized: Promises & Async/Await

Lydia Hallie on April 14, 2020

If you're here in 2024 (or later), here's an updated video: Ever had to deal with JS code that just... didn't run the way you expected it t...
Collapse
 
spoike profile image
Mikael Brassman • Edited

Loving the article and the visualizations!

There is a gotcha however, setTimeout(..., 0) will not immediately put the task to the macrotask queue because of browser throttling. While the result will be the same, the reason why setTimeout fires last is because it is queued up in the macro task queue "a lot" later (4ms) rather than it being a macro task.

That setTimeout is throttled is why Node environment has setImmediate. For more information about browser throttling: developer.mozilla.org/en-US/docs/W...

Collapse
 
vagoel profile image
Varun

Extremely useful and intuitive.
Love the way you describe problem and provide innovative graphical solutions.
Thanks for creating wonderful visuals.

Just wondering what tools you use for creating those. 🧐

Collapse
 
vinstar profile image
Vincent Touquet

Great. I think I understand a lot more now :) I was wondering, how did you make this image? dev-to-uploads.s3.amazonaws.com/i/... I would love to have a node REPL which also shows me the "green" stuff...

Collapse
 
lydiahallie profile image
Lydia Hallie

Haha I just make it manually, sorry! It's a pain to find a repl that shows that..

Collapse
 
conermurphy profile image
Coner Murphy

If you wouldn't mind, what software do you use to make it? I've been trying to figure it out for a while and came up blank. Thanks love the work.

Thread Thread
 
qm3ster profile image
Mihail Malo

I too wish to know this πŸ‘Œ

Thread Thread
 
ziizium profile image
Habdul Hazeez

I use Keynote!

Thread Thread
 
qm3ster profile image
Collapse
 
adgower profile image
Alex Gower

Those are dope.

Collapse
 
selvarajrch profile image

Hi Lydia,

Thanks for writing this up. Great article, enjoyed it and nice animations!!
IMHO, this article is missing one bit and it would be perfect if you can update for the below change.

Now that the async function myFunc is suspended as it encountered the await keyword, the engine jumps out of the async function and continues executing the code in the execution context in which the async function got called: the global execution context in this case!

After this statement, the article can mention this is where the statement console.log('After function') gets executed printing After function to the console.

Thanks.

Collapse
 
charanweb profile image
CHARAN

I got a difference answer when i tried the last code:
Async/await executing the next lines but saving in memory not showing in the output ,until await got the result. And its working synchronously. it shows first await result and executing line by line.


const x = Promise.resolve("Async function")

async function getme(){
 console.log("Before Async")
 const res = await x
 console.log(res)
 console.log("After Async")
}
getme()
//results
 Before Async
 Async function
 After Async
PromiseΒ {<fulfilled>: undefined}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
vitruvius21 profile image
Vitruvius • Edited

You place all console.logs in async function not outside, thus after "Before Async" it sees await, resolves promise and moves the getme() function into the microtasks, since there are no other tasks in callstack, getme() moves back to callstack and executes where it stopped i.e. at await, so res gets initialized, then 'Async function' and 'After Async' are logged.

Collapse
 
silverbullet069 profile image
Silverbullet069 • Edited

This is interesting, you use Promise.resolve function to return a Promise directly, instead of using a callback function that return that Promise.resolve function. This way, you have resolved your Promise right in line 1, not in line const res = await x.

Collapse
 
bearfinn profile image
Kritsada Sunthornwutthikrai

Just a minor suggestion - the visualization says "Timeout!", but the content says. "In timeout!"
Otherwise, it was a very nice article. I know more about the JavaScript queues!

I have a bit of a question. From what I understood, async functions are there to solve the problems where there are functions that took a long time to process such as API calls. However, if the call stack waits for the Promise to resolve, then encounter the await keyword, it means that the execution time will still be similar. Is there any part I misunderstand?

Collapse
 
voanhcuoc profile image
Khoa Che

Only the async functions encountering await will be suspended, other functions - that don't depend on the awaited result - still run.

Collapse
 
martincomito profile image
MartΓ­n Comito • Edited

Thanks A LOT for this post, I been waiting a long time for such a clear explanation of this topic

Collapse
 
lydiahallie profile image
Lydia Hallie

Thank you so much!

Collapse
 
lesha profile image
lesha πŸŸ¨β¬›οΈ

This means that we no longer have to write any Promise object ourselves.

I'd just like to interject for a moment. You still need to write Promises when you actually implement these async functions. Almost all browser and Node APIs are callback-based, not even promise-based so you either need a thin wrapper library that converts them to Promises or do it yourself.

What you don't need anymore is .then chain because that's the whole point of async syntax

Collapse
 
jvor97 profile image
jvor97

Great article, thanks !
I have a question: What would happen if we use an actual http request, e.g. getImage().then(res => console.log('res1')).then(res => console.log('res2'))). getImage body would go into webapi, then into (micro?macro?) queue, and back to callStack where .then would be executed, sent to micro queue and the same process with the next .then...?

Collapse
 
mridubhatnagar profile image
Mridu Bhatnagar

I am not a JavaScript person. Btw, I am very curious to know how did you make these visualizations? Are there any tools you used for this?

Collapse
 
gitshravan profile image
gitshravan

It is so good! I've the same question.

Collapse
 
adriaanbd profile image
Adriaan Beiertz

One of the best, if not the best, explanation of promises. The explanation I wish I had and glad I got to read today. Excellent visuals too!

Collapse
 
lydiahallie profile image
Lydia Hallie

Ah thank you so much! πŸ˜ƒ

Collapse
 
pke profile image
Philipp Kursawe • Edited

Thanks for the writeup!

There is slight room for improvement though I think to just hand in the then handler functions, which in turn receive the correct input automatically that way:

getImage("./image")
  .then(compressImage)
  .then(applyFilter)
  .then(saveImage)
  .then(res => console.log("Success"))
  .catch(error => console.error(error))
Enter fullscreen mode Exit fullscreen mode
Collapse
 
yoshcode profile image
Aljosha Novakovic

Wow who would have known that the event loop is really not that complicated at all, just requires a clear explanation, thank you!

I have one question, I was following everything until the last sentence! But maybe I'm just misunderstanding it:

"...The await keyword suspends the async function, whereas the Promise body would've kept on being executed if we would've used then!"

The await keyword suspends anything below it, within it's scope (the async function), until it is resolved. And if you saved that await call in a variable, you can make use of that return value. This code below the await keyword will be on the microtask queue until it is pushed to callstack and executed, like you very clearly explained. But doesn't the Promise "body" also suspend until it is resolved? The callback that you pass into the .then() will only get executed after our promise has been resolved... and similarly to how we can make use of the value we got from await() if we stored it in a variable, we can make use of the resolved value with .then(data => etc...) So don't technically both of them get suspended equally until they receive the resolved value (or rejected value)? Perhaps I'm just interpreting "Promise body" differently...

Thanks!

Collapse
 
cname87 profile image
cname87

Yes. It's a great article but it should consider the case of awaiting an API call or similar that takes a significant time to return. The simple example using Promise.resolve is not a typical use case. A visualisation of how such api calls would be really useful (although probably time consuming to produce).

Collapse
 
silverbullet069 profile image
Silverbullet069 • Edited

Now I understand "The await keyword suspends the async function, whereas the Promise body would've kept on being executed if we would've used then!"

If you call:

  • a function that return a Promise
  • an anonymous Promise that was defined inside that function.

It will run the callback inside that Promise and resolved that Promise instantly before calling then() since Promise constructor called its callback function.

Okay, now, inside an async function, when you encounters an await statement, you run the awaited command (either a function that return a Promise const res = await thisFuncReturnAPromise(), or that Promise directly const res = await promise), after that, you put that async function inside microstack, waiting to be resumed. That means the async function has been suspended.

P/s: in async function, we all know that async function will return a Promise, but we usually allude this because the return value of an async function is only valuable when that Promise call then() or being passed after await keyword in another async function.

Collapse
 
iosonoagenda profile image
Ettore Ongaro

Maybe if you share a piece of code can be more verbose man

Collapse
 
henok_jskeet profile image
Henok Tesfaye

Finally, there are no more tasks to run in the global execution context! The event loop checks to see if there are any microtasks queued up: and there are! The async myFunc function is queued up after resolving the valued of one. myFunc gets popped back onto the call stack, and continues running where it previously left off.

If we assume function one will resolve eventually after getting http response. Will myFunc added to the micro queue when function one resolves, because if it's added immediately, the event loop will execute it when call stack is empty even if the promise don't resolve? If so there should be a different thread to handle(wait) till promise resolved which didn't cover in the animation.

Collapse
 
ahmadawais profile image
Ahmad Awais ⚑️

Great work, Lydia. I wish you'd use videos instead of Gifs next time, my Macbook Pro is acting out on loading so many gifs. LOL. Respect for all the work you put into this.

Collapse
 
lydiahallie profile image
Lydia Hallie

Yeah I know the pain, I can't change this currently as dev.to doesn't support video 😭

Collapse
 
trasherdk profile image
TrasherDK

Those animations works perfectly.

Had it been a video, I wouldn't have read through your excellent presentation.

Collapse
 
ahmadawais profile image
Ahmad Awais ⚑️

I'd recommend uploading to YouTube an embedding it here. I know it's less than ideal.

Collapse
 
thumbone profile image
Bernd Wechner • Edited

Love it! Awesome piece. I have some residual questions. It's an old article so not sure if you're still around watching and noticing comments and questions. We shall see.

  1. The first relates to the stack. it would help to have another layer of function call to better illustrate the stack with contents, but that aside, I have often seen something like main() which alludes to what you've called the Global Execution Context at the bottom of the stack. For the simple reason that it's commonly written that the event loop regains control (and checks the microtask queue) when the stack is empty. I wonder if you have thoughts on that?

  2. the async/await visualisations are awesome beyond any I have seen yet! I wonder if you would continue with one more article, that covers .then() with this level of clarity.

  3. For all it's awesomeness I am still struggling to understand exactly how the two executor callbacks work, most especially with regard to timing, and the microtask queue. Here is my musing (current thinking) which I'm looking to confirm or correct: When the promise is instantiated it passes a two default callbacks to the executor, and runs the executor immediately (on the stack). A call to the first argument will have the Promise update it's state from "pending" to "fulfilled" and a call to the second will have it updated to "rejected". When the executor is finished (returns) it should have called one of these (or the promise will never resolve). After it has finished the instantiator returns and the promise is one of its three states. A call to .then() (optional) will register one or two callback handlers (for fulfilled and rejected). If the state of the promise is currently fulfilled or rejected it will immediately queues the appropriate callback onto the microtasks queue and return. If the state is pending, then the Promise itself will, as soon as its resolver or rejecter are called queue the appropriate callback then. I'm not sure if that's entirely accurate and would love to see it documented as well as you have if it is, and or what is right if it's not.

  4. When await is used, there is a situation I'm not clear on too. Await works a bit like yield I'm told, and it seems maintains the state of the running async function (on the heap one presumes) and as you write puts the async function on the microtask queue to continue at the same line (which the preserved state enables, though said state could be on the heap or on the microtask queue who knows?). In your example the function one resolves quickly, instantly, but if the function we are waiting on is still pending when the async function reaches the head of the microtask queue and runs once more, what then? I would guess it simply requeues itself. But it would be great to know and to have whatever happens there, so excellently illustrated as you have.

I would be so thrilled if you lent you expert hand at illustrating answers to these. Many many thnaks for the awesome work you have done to date!

Collapse
 
moritzda profile image
MoritzDa

Hey Lydia,
your little article helped me a lot to understand promises better. I didn't know that the engine jumps out of the current function with the await keyword.

I think I found a little mistake in one of your code snippets, the open curly bracket should be removed here? Right?
mistake in code snippet

Thanks for your great article !

Collapse
 
quantum_questor_o7 profile image
Subhransu Nayak

I wish I had known this before watching so many YouTube videos and reading so many articles.
Finally, I was able to obtain a clear concept visualisation of Javascript's Async Behaviour.
I'd like to point out that no video, article, or documentation could provide the same level of concept clarity as this.

Collapse
 
kimo1990 profile image
kimo-1990

I already read all your articles !! wonderfull and genious !! thank you for this huge effort and your articles are very helpful ! just one thing , in the callback hell example above in line 7, shouldn't you say "saveImage ( filteredImage , (res,err) => { "instead of compressedImage . thank you !

Collapse
 
nickytonline profile image
Nick Taylor

Noice! Always great work Lydia.

Noice!

Collapse
 
peachmouse profile image
Michael Stopa

Awesome work, Lydia. What an effort! And very valuable stuff too. Great thanks for sharing.

Collapse
 
aaljo2 profile image
aaljo2 • Edited

I am very impressed your excellent blog. your visualization effort to understand the other interested in the javascript field engineer is very helpful , so Could you please allow me to translate it into Korean?

Collapse
 
shubhambhardwaj profile image
Shubham-Bhardwaj

Ver informative article. Thank you for clarifying everything. But I have doubt "The await keyword suspends the async function, whereas the Promise body would've kept on being executed if we would've used then!" Anything below await goes to the microtask queue and similarly .then callback goes to the microtask queue so how are these two different?

Collapse
 
minhnguyenduy99 profile image
minhnguyenduy99

Thanks for a very intuitive post. I just have one question:

If my server gets swarmed by thousand of requests, each performs an async task. Will all the async tasks wait for all the requests to be put in Event Loop queue before being processed ?

Collapse
 
akfoury profile image
akfoury • Edited

If I understand correctly the setimeout callback doesn't get called after the specified timeout because their might be other microtask queue that are waiting to be called, so the timeout parameter is only there to indicate to web api when to push the callback into the macrotask queue

Collapse
 
courtens profile image
courtens • Edited

there is an error in the image iebp0rzfnfqsrmmjplme.png ... it should be res() and rej(), not resolve() and reject().

Collapse
 
willj518 profile image
William W.

This is terrific. I've used the site for years, but literally signed up because of this article and hoping to find more like this. I'm an SE that is always looking for ways to visualize/map-out concepts and solutions as well. Great job Lydia!

Collapse
 
xavier_gonalves_8964f672 profile image
Xavier Gonçalves

I know I'm a bit late to the party but there are several gifs that simply will not load, and if you try to open them in a new tab, you get "ERROR 9413: Could not resize the image: The animation is too large. Animation resolution is 1080Γ—608, and at this size the maximum number of animation frames allowed is 152 (total area of all frames together must be less than 100000000), but the animation is longer than this", can this be fixed?

Collapse
 
oosharma profile image
Abhishek Sharma

+1

Collapse
 
larsejaas profile image
Lars Ejaas

Thanks a lot for this article! After working with promises and Async code in JavaScript quite a lot recently, I had to take a few steps back and get on top of some of the basics. I stumbled across your article that I really love. Async for dummies! I certainly feel less dumb now! Thanks 😊

Collapse
 
jacksonkasi profile image
Jackson Kasi • Edited

can i know how did ui do this animation. there is any tool there?

Collapse
 
gphirke profile image
gphirke • Edited

As soon as setTimeout api is encounter, its gets pushed out from execution callstack to webapi. Now when Promise encounter, its cb function gets pushed out to microtask callback queue. In terms of setTimeout I can understand that its WEB-API pushing cb function after timeout, but in case of promise (suppose it takes 2 min to get response from API) then how that point is trigger to push promise cb to microtask? (if it is part of JavaScript engine only why not execution is stucking there?)

Collapse
 
tomurb profile image
Tomek Urban

Hi, I think I'm at the beginning but I think there is some mishap in one of the images res.cloudinary.com/practicaldev/im...
Shouldn't Promise constructor arguments names be the same as functions in try and catch blocks?
I hope it hasn't been pointed out before, but I have no time, gotta get back to reading of this gem ;)

Collapse
 
tirestay profile image
tirestay

Hi Lydia
This an amazing article, also others that demonstrating by animation.

I want to ask you permission to translate your articles to Chinese to help more persons, also should have the original post link of this course.

Collapse
 
paulius1 profile image
Paulius ValiΕ«nas

I've recommended this article to people for years, but now it fails to load most of the animations. Looking at the browser debugger's network tab, they're all failing to load with 403 and a response body like:

ERROR 9413: Could not resize the image: The animation is too large. Animation resolution is 1080Γ—608, and at this size the maximum number of animation frames allowed is 152 (total area of all frames together must be less than 100000000), but the animation is longer than this

Seems like dev.to updated their CDN with more restrictive limits... is there any way you could embed them without resizing? Or manually resize them so they're all 800px wide (that's what dev.to tries to resize them to before loading, at least in my browser)?

Collapse
 
mj_tan_1feaea89a745aa30f3 profile image
Major Tan

Hi Lydia, great work ! However, there are around 8 disabled animated pictures for this article. For example, the ones at .then and .catch are disabled. I also discovered similar information can be viewed at medium website. Could you please fix the reading problem ? I also have sent you an email about a PDF edition. Hope you have received it in your inbox.

Collapse
 
threetowns profile image
leon

I think the [[PromiseStatus]] should be [[PromiseState]], the [[PromiseValue]] should be [[PromiseResult]] in this article.

Collapse
 
windvalley profile image
XG

The first thing that happens is that the value that gets awaited gets executed: the function one in this case. It gets popped onto the call stack, and eventually returns a resolved promise. Once the promise has resolved and one returned a value, the engine encounters the await keyword.

The given description above seems to be a bit misunderstood regarding how async/await works in JavaScript.
The engine doesn't "encounter the await keyword" after the promise resolves. Rather, it encounters await as it is executing the async function, then waits for the promise to resolve before moving on with the rest of the function's code. During this waiting period, the execution context of the async function is suspended, and control returns to the event loop, allowing other operations to run.
And the promise itself isn't "popped onto the call stack" but is instead being handled by the JavaScript engine's promise handling mechanism, which is separate from the call stack.

Thanks a lot for this article. Greate work!

Collapse
 
ganeshbehera profile image
ganesh

I want to visualise this code using call stack, web API, microtask queue, macrotask queue, event loop
But I am unable to visualise it.
Can you plz help me out to visualise it means can you plz explain it to me?
Thanks

Code snippet:

function a(){

return new Promise((resolve, reject)=> {

setTimeout(()=> { console.log("a"); resolve(); },4000)

})

}function b(){

return new Promise((resolve, reject)=>{

setTimeout(() => { console.log("b"); resolve(); }, 2000) })

}function c(){

return new Promise((resolve, reject)=>{ setTimeout(()=>{

console.log("c"); resolve(); },6000)})

}function d(){

return new Promise((resolve, reject)=>{

setTimeout(() => { console.log("d"); resolve(); },10000)})
}

a()

.then(() => {return b()})

.then(() => {return c()})

.then(() => {return d()})

.then(() => {

console.log("All finished");

})

.catch((err)=>{

console.log(err);

})

console.log("Hello");

Output:
Hello
a( after 4sec of "hello" print)
b(after 2sec of "a" print)
c(after 6sec of "b" print)
d(after 10sec of "c" print)

Collapse
 
bsilvers64 profile image
Bhavansh sthapak

Hi! excellent article, I had one doubt though. at the end you mentioned that await keyword would suspend the async function and promise body would've kept on being executed if we would've used "then", but doesn't the then method also gets transferred to the microtask queue after the promise is resolved, so the code in the global execution context would continue first ?

Collapse
 
frankgo81 profile image
FRANK GO

amazing!!!!

Collapse
 
dimacros profile image
dimacros

Hello, I really like your post, I have a question, how do you generate those gifts? What kind of tools do you use to do that? please

Collapse
 
iosonoagenda profile image
Ettore Ongaro

Probably some AI

Collapse
 
aneeqakhan profile image
Aneeqa Khan

Very helpful! Thank you

Collapse
 
voglerr profile image
Ralf Vogler

Once the promise has resolved and one returned a value, the engine encounters the await keyword.

Should have used a Promise that gets added to the queue here. The sentence makes it sound like evaluation waits for any Promise to be resolved before encountering await.

Collapse
 
voglerr profile image
Ralf Vogler

Did you notice how async functions are different compared to a promise then? The await keyword suspends the async function, whereas the Promise body would've kept on being executed if we would've used then!

Isn't async/await just syntactic sugar for Promise-chains? There may be some differences in implementation, access to labels etc., but you make it sound like they have different semantics regarding execution.

Collapse
 
yanniloboa profile image
Vuyani DawetiπŸ•³πŸ€Ύβ€β™‚οΈ

"Yes! However, within the Event Loop, there are actually two types of queues: the (macro)task queue (or just called the task queue), and the microtask queue. The (macro)task queue is for (macro)tasks and the microtask queue is for microtasks."

Correction

*Event Loop has six phases
*

  • Poll (i/o execution)
  • Check (setImmediate() )
  • Close ( Event Emiiters)
  • Timers (setIntrrlerval and SetTimeout)
  • Pending (specific system event such as net. Sockets)
  • Prepare ( deferred callbacks during phase execution)

These phases are executed sequencially

*Each phase has two micro tasks *

  • Process.nextTick()
  • Promises

each phase has task two micro tasks Process.nextTick and Promises
Process.nextTick is executed before Promises.

Collapse
 
saver711 profile image
Ahmed Hasan

@lydiahallie
can you please provide me with this gif from the beggining to the end
res.cloudinary.com/practicaldev/im...

Image description

Collapse
 
hoanggia7398 profile image
hoanggia7398

great post!

Collapse
 
plikepatrick profile image
Patryk BΕ‚aszczak • Edited

Hey, great post, I have learned so much, thanks for that! But there is one thing I still can't figure out, let's say we've got couple chained then() methods, once we invoke the promise constructor, the callback is being registred as a handler for resolved data, so once this happend the callback from that then() method gets to microtask queue. My question here is what happens to the next chained then() methods? is it that once the first then() callback is invoked in the call stack and returns promise, then next calback from next then() method is being queued to the microtask queue? I hope it does make sense, I still learn english :)

Collapse
 
becksinha89 profile image
Rebekka Haas • Edited

Lydia - absolutely great explanations. We hold an internal knowledge Workshop on the topic and showed your visualization. Can we share the microtask queue visualization on our homepage in the context of our house-intern workshop?

Collapse
 
tyroneweb profile image
薛清扬

it helps me understand a lot about Promise and async function. Thanks

Collapse
 
gschro profile image
gschro

This is fantastic, love the whole series!

Collapse
 
atl3tico profile image
atl3

Great article and excelent GIFs

Saving to share with all collagues

Btw: there's a typo in res.cloudinary.com/practicaldev/im...

resolve is not found

Collapse
 
gabrielecimato profile image
Gabriele Cimato

I cannot even imagine how long it took to make this post! Absolutely stellar!

Collapse
 
jkgan profile image
Gan Jun Kai

This is soooo cool! May I know what tool you using to make the visualize stuff?

Collapse
 
amiddrisu profile image
Iddrisu Abdul-Manan

To say that, I am impressed is a huge understatement. Only one word can describe this magnificent article and that is AWESOME. Keep up the great work. Super Lydia!

Collapse
 
vaibhavkhulbe profile image
Vaibhav Khulbe

Super cool explanation and thanks for adding that GitHub repo at the end. Stay safez...!

Collapse
 
alainfou profile image
Alain

Hi Lydia ! Great job !!
:D
Also, I know it's a very small typo, but you seem to have one opening bracket { too many in your image: res.cloudinary.com/practicaldev/im...
and since we're talking about code, I guess it'd break ^^

Thanks for opening the path for me to using async/await !

Collapse
 
nikla profile image
Nikla

Great read, love the visuals. Thanks a lot.

Collapse
 
oleglzn profile image
Oleg Luzenin

the article contains many wrong images, which are not being rendered correctly on the page

Collapse
 
shubhamdeol profile image
Shubham Choudhary • Edited

So micro task callback doesn't get pushed to web api's ?

Collapse
 
trippymonk profile image
Blake Stansell

This is fantastic! Great explanations :)

Collapse
 
mertocak profile image
Mert Ocak

Very good, thank you!

Collapse
 
blueboy6 profile image
BlueBoy6

Realy nice article about promises, probablly one of betters i read !

Collapse
 
gokulnath31 profile image
Gokulnath31

The images seems to be broken for async/await explanations @lydiahallie ?

Collapse
 
dvddpl profile image
Davide de Paolis

excellent article!

Collapse
 
pradeepchinwan profile image
pradeepchinwan

Really its Great. I think I understand a lot more now :)
Thanks alot 😊

Collapse
 
renancferro profile image
Renan Ferro • Edited

Jesus, this article is just perfect! Congratulations!

Collapse
 
rickydazla profile image
Rick Davies

This is so good! Admittedly a little drunk and faded out toward the end but I’ll come back fresh... I promise:D

Collapse
 
prajwalscorpionking123 profile image
PRAJWAL PATIL

Nicely explained.. really awesome..

Collapse
 
prafulla-codes profile image
Prafulla Raichurkar

Hey Lydia!

I am loving the series so far, thank you for all the stunning visuals and cool explanations.

Can't wait for more of these!

Collapse
 
elamiir profile image
El-amiir

Great article, Thanks ^^

Collapse
 
fritzlolpro profile image
Fedor

Thanks!
Visualisation is really cool!
When somebody asks me how this stuff works Ill send your article

Collapse
 
victorsamson profile image
Victor Samson

Such a great article! Thank you!

The visualisation made things very clear.

Now to go back and read all the previous ones in the series!

Collapse
 
chakrihacker profile image
Subramanya Chakravarthy

Wow this is great explanation

Collapse
 
jacobmgevans profile image
Jacob Evans

This is awesome! I was wondering what you used for all the animations?

Collapse
 
malekabbes profile image
Malek abbes

Great post Lydia , thanks alot for this βœ‹πŸΌ

Collapse
 
mamunahmed profile image
Mamun Ahmed

Great article!

Collapse
 
kosoko_daniel profile image
Oluwagbenga

I haven't read this yet but I can't wait to do so.
You did a lot of work here.

Collapse
 
hdlinhit95 profile image
Lin

Great! Very helpful!. I really appreciate the details of this article! So I'll definitely follow up with your next posts. Thanks!

Collapse
 
sayuj profile image
Sayuj Sehgal

Great article, Seriously I was very confused with Promises and Async/Await concept, after reading this article I am feeling pretty comfortable and confident. Thanks for writing this article😊.

Collapse
 
eje_sunay profile image
Eje Sunay

This is so perfect, i love every bit of it. thanks a thousand times

Collapse
 
juliyashi profile image
JuliyaShi

Awesome, thanks for your explanation)

Collapse
 
digituar profile image
digituar

I think it's the best explanation I've ever read. With the animations it makes things even easier. Many thanks for the excellent work Lydia. Keep it up. Many many thanks

Collapse
 
yurichaikovsky profile image
YuriCahikovsky

Thanks a lot!!!

Collapse
 
ayeshaazam profile image
Ayesha

Thanks alots Lydia for this excellent article, you make things easy to understand :)

Collapse
 
xgqfrms profile image
xgqfrms

awesome gif

Collapse
 
mat3uszkek profile image
Mateusz SkrobiΕ›

beautiful article, thank you very much! :)

Collapse
 
newninja12345 profile image
Mengistu

Thanks for making my life easier!

Collapse
 
maoxoam profile image
maoXoam

THANK YOU SO MUCH, miss Lydia.
may I ask is requestAnimationFrame(()=>console.log('rAF')) this callback function belongs to macrotask?

Collapse
 
miteshkamat27 profile image
Mitesh Kamat

Thats a cool visualization.

Collapse
 
leonangelit profile image
LeonAngelit

Nice! Thank you for this!.

What happens when the Promise have a setTimeout inside? the microtask stops until this Promise is fulfilled?

Collapse
 
lorrehuggan profile image
Lorre Huggan

This was weel worth the read and really clarified some concepts that where hazy to me.
Thank you 😁

Collapse
 
ashutoshmishra profile image
Ashutosh Mishra

This is the best article I have ever read on JavaScript,

How did you create such amazing animated GIFs??

Collapse
 
zhuangyin8 profile image
zhuang • Edited

error: which logs the string "In timeout!". => which logs the string "Timeout!".

error: we can pass that value to a resizeImage function => we can pass that value to a compressImage function

Collapse
 
subratcodes_78 profile image
Subrat Kumar Singh

Top Notch !!!!

Collapse
 
paulodon profile image
Paul Odon

This post is the best... Very clean... Thank you @lydiahallie

Collapse
 
daslaw profile image
Dauda Lawal

Nice

Collapse
 
yummta profile image
Paul Portillo

Thank you very much for making such a detailed explanation of all this🀩. YOU ARE AWESOME! πŸŽ‰

Collapse
 
hisaponz profile image
narutokun • Edited

Finally figured out Promise and async! Thanks!!
Nice color and good movement!

Collapse
 
ganeshavala profile image
ganeshavala

Just amazing work. Kudos to Lydia for the art of explaining Javascript concepts.

Collapse
 
arunsraga profile image
Arun

Good Article and visualisations are very helpful for understanding the concepts.

-- Thank You

Collapse
 
yoshixj profile image
yoshiki masubuchi

thank you for this writing this post!
This visualization is great help to understand JS for me !!

Collapse
 
mightytechno profile image
Mighty

Really good

Collapse
 
artem_bardachov_ profile image
Artem Bardachov

God bless you! The best explanation ever!

Collapse
 
asish0sahu profile image
Asish kumar sahu

Nice explanation Lydia :) πŸ€—Love this using JS 🌟

Collapse
 
aaljo2 profile image
aaljo2

I'm very impressed your detail blog , and visualization easily to understand the technique, even if difficulty to understand , could I translate your blog into Korean ?

Collapse
 
mrexamples profile image
Mrexamples

really very impressive work, amazing visualizations providing much ease to the learners. keep up the good work!

Collapse
 
orivolfo profile image
Ori Volfovitch

Great job!
Explanations with visualizations are the best.
Thanks for the hard work.

One minor nitpicking I couldn't hold myself - Promises existed before ES6.

Collapse
 
mrakonja profile image
Mladen Milosavljevic

I needed this. Ty.

Collapse
 
segolenealquier profile image
Ségolène Alquier

This is an amazing article, the best I've read on the subject! 😍
(And I've been struggling with asynchronous JS and reading a loooooot of things on that topic...)
KEEP UP THE EXCELLENT WORK πŸ™Œ

Collapse
 
gfxargentina profile image
gfxmotion

Great article!!!, I could finally understand this, please keep making articles like these explaining javascript, thanks a lot!!! greetings from Argentina

Collapse
 
emmaindal profile image
Emma Indal

Again, thank you so much for explaining and visualizing JS concepts so it becomes so much more clear! πŸ’›πŸ™ŒπŸ»

Collapse
 
feinimoshu753 profile image
edward

I like this post. It is very easy to understand.

Collapse
 
frontendmetis profile image
Rustam

Perfect explained, thx

Collapse
 
tienthanhjlw profile image
Nguyα»…n TiαΊΏn ThΓ nh

Awesome!

Collapse
 
samuelalsn profile image
SamuelALSN

Excellent post , please which software did you use to draw your post

Collapse
 
stealthmusic profile image
Jan Wedel

Thanks, those are awesome visualizations and explanations! I was recently trying to explain that no code really happens in parallel In JS and this article would have helped a lot πŸ‘

Collapse
 
navinmishra1717 profile image
Navin Mishra

Great article and visualization. Read and loved every part of it. thanks!!

Collapse
 
fly profile image
joon

Outstanding visualization

Collapse
 
twisterrob profile image
RΓ³bert Papp

Hey, @lydiahallie, the original code with callbacks has a bug in it, the compressed image is used twice.

Collapse
 
ameenshah profile image
Ameen Shah

great articleπŸ‘πŸ‘πŸ‘

Collapse
 
tarektaamali profile image
tarektaamali

Hi @lydiahallie what's Tools are you used in design of the graph(images)

Collapse
 
cyberorca profile image
cyberorca

wow, it's amazing visualization ! thanks for the article..

Collapse
 
shinthant profile image
Shin Thant

Thank you! This is a very great article.

Collapse
 
diegolopes87 profile image
diegolopes87 • Edited

Absolutely great post!

This kind of explanation should definitively be shared

Do you mind if I translate your post?

Collapse
 
khaledalwakel profile image
khaled-alwakel

excellent !
thank you so much

Collapse
 
dvirhanum profile image
Dvir Hanum

High quality

Collapse
 
reavielx profile image
Claudio

Finally someone wrote it like for an idiot :D Thank you

Collapse
 
jwaibsnaider profile image
jwaibsnaider

Hi! @lydiahallie :) Could i translate those topics to my language (Im from Argentina) and post in Linkedin! I would like to tag you also there :):):):):)

Collapse
 
himanshushekharcu profile image
Himanshu Shekhar

Hey Lydia, Can you create such visualisation for 'this' in JS

Collapse
 
gcmo profile image
GCMO

Can you recommend a site where we can practice some Promise and Async/Await exercises? Thanks!

Collapse
 
kazinoman profile image
kazinoman

I just Love this...

Collapse
 
plondon profile image
Philip London

Hi Lydia!

Great article! Thank you! I've adapted it to be a codeamigo lesson (codeamigo.dev/lessons/88) so that users can interact with the code as they learn, hope it helps someone!

Collapse
 
ayush2020012016 profile image
Ayush Nautiyal

i am blessed.

Collapse
 
lluthus profile image
Lluthus

Dear, about ur last example. What about I should give back the "one" result to a sync function caller in order do something. Is it unfacible ? I love the way you are explaining. Best regards

Collapse
 
isaevrustam profile image
Isaev-Rustam

Thank you )

Collapse
 
mosalem profile image
Mohamed Salem

I love you and your way to explain JS
you are my hero here

Collapse
 
derryderajat profile image
derry derajat

how to make those beautiful visualization?

Collapse
 
drgaud profile image
DrGaud

You aboslute legend, thank you, been trying to wrap my around this for the past few days.

Collapse
 
aliajafari profile image
Ali A. Jafari

Such a useful post & so deep

Collapse
 
mujtababasheer profile image
mujtaba-basheer

Great article, now these concepts are very clear to me.

Collapse
 
lorebianchi profile image
Lorenzo Bianchi

Great article! Clear and concise explanation ... thank you very much Lynda

Collapse
 
nandansn profile image
Nandakumar R

Thanks

Collapse
 
science_and_fun profile image
Science ∞ FunπŸ›°πŸŒ πŸ•³πŸš€πŸ€–πŸ§ͺβš—πŸ“βš™πŸ§¬πŸ˜ƒ

That is cool!πŸ‘

Collapse
 
vasilevski95 profile image
Djordje Vasilevski

Helpful. Ty.

Collapse
 
eshukumar profile image
eshu-kumar • Edited

Great visualisation way of explaining such complex topic . You made it very simple thanks Lydia πŸ™

Collapse
 
gianlucajahn profile image
Gianluca Jahn • Edited

Great article, thanks for the (smooth) visualization!

Collapse
 
iamamitesh profile image
iamAmitesh

i got this article one night before exam!!!.....I LOVED IT
extremely useful.

Collapse
 
jmsherry profile image
James Sherry

What about animation callbacks, like requestAnimationFrame? They have a different behaviour too! (See https://www.youtube.com/watch?v=cCOL7MC4Pl0&ab_channel=JSConf)

Collapse
 
humblecodes profile image
humble-codes

Thank you very much for the lovely article