r/javascript • • Mar 18 '19

What's your favorite, most useful javascript one-liner?

385 Upvotes

422 comments sorted by

View all comments

Show parent comments

3

u/EllisLloyd Mar 25 '19

Because when you use await on it it looks like synchronous code. How are you going to use setTimeout in purely imperative code without screwing up your flow?

1

u/reyhanahmed Mar 25 '19

Yeah, so without using promise the code below setTimeout will run right after registering the setTimeout callback in the event loop. But if we use promise, it will stop the execution of the funtion right?

2

u/EllisLloyd Mar 25 '19

Yeah exactly

1

u/reyhanahmed Mar 25 '19

Cool, thanks!