JavaScript · Senior · Question 50 of 75

Why shouldn't you pass an async function as the executor in new Promise(async (resolve) => ...)?

Explanation

The constructor ignores the promise returned by an async executor, so an exception after await becomes an unhandled rejection, and the outer promise stays pending. If there's already an await inside, the new Promise wrapper usually isn't needed at all - an async function is enough.

Further reading

Problem with a question

JavaScript · Senior · question 50

Test yourself

Take the JavaScript · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz