FrontendDeveloper.in

JavaScript question detail

Why do you need a promise

Promises are used to handle asynchronous operations, especially in languages like JavaScript, which often work with non-blocking operations such as network requests, file I/O, and timers. When an operation is asynchronous, it doesn't immediately return a result; instead, it works in the background and provides the result later. Handling this in a clean, organized way can be difficult without a structured approach.

Promises are used to:

  1. Handle asynchronous operations.
  2. Provide a cleaner alternative to callbacks.
  3. Avoid callback hell.
  4. Make code more readable and maintainable.
Back to all JavaScript questions
Get LinkedIn Premium at Rs 399