How do you promisify a callback-based function in JavaScript?
Wrap it in a Promise. Call the original function with a callback that calls reject on error and resolve on success. Return the Promise. Node.js has util.promisify for this.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in Callback Interview Questions in JavaScript
Deeply nested callbacks that are hard to read and maintain. Each async operation depends on the previous one, leading to a pyramid shape. Fix with promises (chain .then calls) or async/await (flatten to synchronous-looking code).
When you pass a callback to a function, you give up control of when and how it is called. The function might call it multiple times, not at all, or with unexpected arguments. Promises solve this by guaranteeing the callback is called once.
The Node.js convention: the first argument is an error. Always check if (err) first and handle it. In promises, use .catch instead. Never ignore the error argument in a callback.
Still have questions?
Browse all our FAQs or reach out to our support team
