CodeZettaInterview Hub

JavaScript · Promises · Fresh / Intern · Concept

What is a Promise in JavaScript?

Short Interview Answer

A Promise is an object representing the eventual fulfillment or rejection of an asynchronous operation, with states pending, fulfilled, or rejected.

Detailed Explanation

Promises provide a standard composable abstraction for async results. Once settled, a promise's state is immutable. Consumers attach `.then`, `.catch`, and `.finally` handlers, which themselves return promises enabling chaining. Creating with `new Promise((resolve, reject) => ...)` should not do heavy sync work beyond starting async ops. Prefer returning promises from APIs over mixed callback styles. Promises integrate with `async/await` and the microtask queue.

Example

const p = new Promise((resolve, reject) => {
  setTimeout(() => resolve('done'), 100);
});
p.then((v) => console.log(v));

Interview Tip

Mention immutability of settled state.

Common Mistake

Thinking you can 'reset' a promise back to pending.

Did you know this answer?