Facebook Pixel

Can promises be cancelled in JavaScript?

Promises themselves cannot be cancelled. But fetch and some other APIs support AbortController: create a controller, pass its signal to fetch, and call controller.abort() to cancel.

Verify This Answer

Cross-check this information using these trusted sources:

More FAQs in How Promises Solve Callback Problems in JavaScript

Promises use .then chains instead of nested callbacks. Each .then returns a new promise, so you can chain flatly instead of nesting. This eliminates the pyramid of doom.

A promise settles exactly once. resolve/reject can only be called once. .then callbacks always run asynchronously as microtasks. You trust the promise spec, not the function calling the callback.

One .catch at the end of a .then chain handles errors from anywhere in the chain. With callbacks, each callback must check if (err) and propagate, which is repetitive.

Still have questions?

Browse all our FAQs or reach out to our support team

Want to upskill yourself?

Our courses are taking a Coffee break, but your curiosity shouldn't. Stay engaged with namastedev linkedin, youtube, discord and other resources while you wait.

0
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.