Return executes before forEach is completed. As forEach is async
Arjun Nair

You are close, Arjun, but in fact the return is not making much difference here (if you remove it and run the code again you can see the result is the same). Please have a look on Daniel’s response for a more detailed explanation.

Also, forEach is not actually asynchronous in this usage here, it's blocking (meaning the code will wait for its full execution before proceeding with the next line).

One way forEach would be asynchronous if is we used async/await with it, just like in this example here:

Like what you read? Give Tiago Romero Garcia a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.