How can you create a new Promise?

  • Using the new Promise() constructor
  • Using the async/await syntax
  • By directly returning a value
  • Using the try/catch block
You can create a new Promise in JavaScript using the new Promise() constructor. This constructor takes a single argument, a function, which in turn takes two parameters, resolve and reject. Inside this function, you define the asynchronous operation, and when it's complete, you call resolve with the result if it's successful or reject if there's an error.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *