Facebook Pixel

What is a promise in JavaScript?

An object representing the eventual result of an async operation. It is a placeholder for a future value. A promise has three states: pending, fulfilled, and rejected. It settles (fulfills or rejects) exactly once.

Verify This Answer

Cross-check this information using these trusted sources:

More FAQs in What Are Promises in JavaScript?

Pending (initial, not yet settled), fulfilled (operation succeeded, has a value), and rejected (operation failed, has a reason/error). A promise transitions from pending to fulfilled or rejected once and cannot change state after settling.

Use new Promise((resolve, reject) => { ... }). The executor function runs immediately. Call resolve(value) to fulfill the promise, or reject(reason) to reject it. The executor usually starts an async operation.

Promises guarantee once-only settlement (no inversion of control), enable flat chaining with .then, use a single .catch for all errors, provide Promise.all for parallel operations, and enable async/await for synchronous-looking code.

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.