Explorer
Node.js

A Promise represents a value that may be available now, later, or never. States: 1. Pending: Initial state. 2. Fulfilled: Operation completed successfully. 3. Rejected: Operation failed. Key Methods: - .then(onFulfilled, onRejected): Chain operations. - .catch(onRejected): Handle errors. - .finally(onFinally): Always runs. Static Methods: - Promise.all([]): All must fulfill. Rejects if any rejects. - Promise.allSettled([]): Waits for all to settle. - Promise.race([]): First to settle wins. - Promise.any([]): First to fulfill wins. Microtask Queue: - Promise callbacks (.then, .catch) are microtasks. - Microtasks run between event loop phases. - process.nextTick() runs before Promise microtasks.

Problem Statement

A Promise represents a value that may be available now, later, or never. States: 1. Pending: Initial state. 2. Fulfilled: Operation completed successfully. 3. Rejected: Operation failed. Key Methods: - .then(onFulfilled, onRejected): Chain operations. - .catch(onRejected): Handle errors. - .finally(onFinally): Always runs. Static Methods: - Promise.all([]): All must fulfill. Rejects if any rejects. - Promise.allSettled([]): Waits for all to settle. - Promise.race([]): First to settle wins. - Promise.any([]): First to fulfill wins. Microtask Queue: - Promise callbacks (.then, .catch) are microtasks. - Microtasks run between event loop phases. - process.nextTick() runs before Promise microtasks.

Complexity

Time Complexity: -

Space Complexity: -

Hints

Review the concept description to prepare for your interview.

Promises and the Microtask Queue

Easy
A Promise represents a value that may be available now, later, or never. States: 1. Pending: Initial state. 2. Fulfilled: Operation completed successfully. 3. Rejected: Operation failed. Key Methods: - .then(onFulfilled, onRejected): Chain operations. - .catch(onRejected): Handle errors. - .finally(onFinally): Always runs. Static Methods: - Promise.all([]): All must fulfill. Rejects if any rejects. - Promise.allSettled([]): Waits for all to settle. - Promise.race([]): First to settle wins. - Promise.any([]): First to fulfill wins. Microtask Queue: - Promise callbacks (.then, .catch) are microtasks. - Microtasks run between event loop phases. - process.nextTick() runs before Promise microtasks.
Editor
Loading Editor...
Output:Click "Run" above to execute and verify your code here.