DEV Community

Discussion on: 10 JavaScript Quiz Questions and Answers to Sharpen Your Skills

Collapse
 
salyadav profile image
Saloni Yadav

Well picked examples. I got something similar to question 8 in one of the js interviews. Also, could you explain question 5 a little more in terms of the event loop? Why promise.all returns in the same order... wouldn’t the event loop resolve based on the settimeout delay once the promise is returned? Thanks

Collapse
 
haidv profile image
HaiDV • Edited

Promise.all waits all promised to be resolved. That 's the simplest explanation

Collapse
 
salyadav profile image
Saloni Yadav

Yes. But my question is regarding the order of printing.

Thread Thread
 
haidv profile image
HaiDV

It also ensure the order of data from promises. More info here: developer.mozilla.org/en/docs/Web/...

Thread Thread
 
salyadav profile image
Saloni Yadav

Thank you for the reference. :)

Thread Thread
 
ribizlim profile image
Mark Magyarodi

the console.log is done only once after all promises are resolved, not for each timeout

Thread Thread
 
salyadav profile image
Saloni Yadav

Will not the print be in the order of resolution even if they are all printed after all the promises are resolved?

Thread Thread
 
ribizlim profile image
Mark Magyarodi

No, Promise.all takes an array off promisses and resolves to an array of all promise results in the same order. The array is what will be printed...

Thread Thread
 
salyadav profile image
Saloni Yadav

Okay!! this is the exact clarification I was looking for! Thank you! :)