JavaScript · Senior · Question 3 of 75

Does the new Promise(executor) executor function run synchronously?

new Promise(() => console.log("A"));
console.log("B");

Explanation

The executor is called right away in the constructor. Only then/catch/finally callbacks are asynchronous - they always run as microtasks, even if the promise is already settled. This guarantees a predictable code order.

Further reading

Problem with a question

JavaScript · Senior · question 3

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