Why does the `then()` handler of a promise execute immediately?

promise.then(alert('after delay'));

Here you:

  1. Call alert()
  2. Pass its return value to then()

So the promise doesn’t resolve immediately. You just alert before it resolves.

You have to pass a function to then.

promise.then(alert.bind(window, 'after delay'));

Leave a Comment