Executor Runs Immediately
You'll learn that the Promise executor function runs synchronously the instant you call new Promise(), not later.
The Core Idea
When you create a Promise using the constructor, the executor function you pass in doesn't wait—it runs immediately and synchronously during the Promise's construction. This happens before any .then() handlers can run, and before the current script even finishes executing.
Think of it like ordering a coffee: the moment you say "I'd like a latte," the barista starts writing your order down right now—not later when you sit down. The executor is that immediate acknowledgment and setup.
Why This Matters
Many developers assume Promise executors are automatically asynchronous, but they're not. The executor runs right away on the current call stack:
console.log('Before Promise');
const myPromise = new Promise((resolve, reject) => {
console.log('Inside executor');
resolve('Done');
});
console.log('After Promise');
// Output:
// Before Promise
// Inside executor ← runs immediately!
// After Promise
Notice "Inside executor" prints before "After Promise". The executor ran synchronously during the new Promise() call itself.
Synchronous Setup, Asynchronous Resolution
The executor runs immediately, but what you do inside it (like calling setTimeout or fetching data) can still be asynchronous. The resolution of the Promise happens async, but the executor function itself doesn't:
const myPromise = new Promise((resolve) => {
console.log('Executor runs now');
setTimeout(() => resolve('Later'), 1000);
});
console.log('After creating Promise');
// Executor runs now
// After creating Promise
// (1 second passes, then Promise resolves)
Key Takeaway: The executor function runs immediately and synchronously when new Promise() is called—it's not deferred or queued like Promise resolution callbacks.