Facebook Pixel

Promise Interview Questions in JavaScript

Promises are a top interview topic. Here are the most asked questions with answers and code.

Promise Interview Questions in JavaScript

Promises are a top interview topic. Here are the most asked questions with answers and code.

Q1: What is a promise?

An object representing the eventual result of an async operation. Three states: pending, fulfilled, rejected. Settles once.

Q2: What is the output?

console.log("1"); Promise.resolve().then(() => console.log("2")); console.log("3"); `` **Answer**: `1, 3, 2`. `.then` is a microtask; it runs after the synchronous code. ### Q3: What is the output? ```js Promise.resolve(1) .then((n) => n + 1) .then((n) => console.log(n)); `` **Answer**: `2`. Each `.then` passes its return value to the next. ### Q4: What is the output? ```js Promise.resolve(1) .then((n) => { n + 1; }) .then((n) => console.log(n)); `` **Answer**: `undefined`. The first `.then` has a block body with no `return`. ### Q5: What is the output? ```js Promise.reject(new Error("oops")) .then((v) => console.log("then", v)) .catch((err) => console.log("catch", err.message)); `` **Answer**: `catch oops`. The `.then` is skipped (promise rejected); `.catch` runs. ### Q6: What is the output? ```js Promise.resolve(1) .then((n) => { throw new Error("oops"); }) .then((n) => console.log("skipped")) .catch((err) => console.log(err.message)); `` **Answer**: `oops`. The throw skips the next `.then` and goes to `.catch`. ### Q7: What is the output? ```js Promise.resolve(1) .catch((err) => console.log("catch")) .then((n) => console.log("then", n)); `` **Answer**: `then 1`. `.catch` only runs on rejection. Since the promise is fulfilled, `.catch` is skipped and `.then` receives 1. ### Q8: What is the output? ```js Promise.all([Promise.resolve(1), Promise.resolve(2), Promise.resolve(3)]) .then((results) => console.log(results)); `` **Answer**: `[1, 2, 3]`. `Promise.all` waits for all and returns results in order. ### Q9: What is the output? ```js Promise.all([Promise.resolve(1), Promise.reject("err"), Promise.resolve(3)]) .then((results) => console.log(results)) .catch((err) => console.log("catch", err)); `` **Answer**: `catch err`. `Promise.all` rejects if any promise rejects. ### Q10: What is the difference between Promise.all and Promise.allSettled? `Promise.all` rejects if any promise rejects (fast fail). `Promise.allSettled` waits for all and returns `[{ status, value/reason }]` for each. ### The Takeaway Promise interview questions test: the definition, microtask ordering (promises run after sync), chaining (return values), error handling (`.catch` catches throws and rejections), `.catch` on a fulfilled promise (skipped), and `Promise.all` vs `Promise.allSettled`.

1, 3, 2. The .then callback is a microtask; it runs after the synchronous code (1 and 3) completes and the call stack is empty.

The error propagates to the next .catch in the chain. Subsequent .then callbacks are skipped. If there is no .catch, it becomes an unhandled rejection.

No. .catch only runs when the promise rejects or a .then above it throws. If the promise is fulfilled, .catch is skipped and the next .then receives the value.

Promise.all rejects if any promise rejects (fast fail). Promise.allSettled waits for all promises, even if some reject, and returns an array of { status, value/reason } objects.

Because arrow functions with block bodies (=> { ... }) need an explicit return. Without return, the function returns undefined, and the next .then receives undefined. Use an expression body (=> expr) or add return.

Ready to master React completely?

Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course to dive deeper with high-quality video tutorials, solve interview questions, and a premium community.

Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.