Facebook Pixel
How Promises Solve Callback Problems in JavaScript

Can promises be cancelled in JavaScript?

The answer

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.

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?

Your learning library

Small steps. Big possibilities.

Find your next course. Build something great.

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

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.