JavaScript · Senior · Question 50 of 75
Why shouldn't you pass an async function as the executor in new Promise(async (resolve) => ...)?
- ✓Correct answer: An error after
awaitwon't reject the promise - it hangs - 2The
Promiseconstructor throwsTypeErrorfor any async function - 3It works, but the executor and the promise run twice
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.