VOOZH about

URL: https://www.geeksforgeeks.org/javascript/javascript-promise-constructor/

⇱ JavaScript Promise constructor - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

JavaScript Promise constructor

Last Updated : 23 Jul, 2025

JavaScript Promises are used to handle asynchronous operations in JavaScript. They are easy to manage when dealing with multiple asynchronous operations where callbacks can create callback hell leading to unmanageable code.

Promise constructor in JavaScript is mainly used to wrap functions that do not already support promises.

Syntax:

new Promise(executor)

Parameters: The promise constructor contains a single parameter:

  • executor: The executor can be the custom code that ties an outcome to a promise. You, the programmer, write the executor. 

Return Value: Another promise object, in which case the promise gets dynamically inserted into the chain.

Example 1: Creating only one promise constructor.


Output
Promise { <pending> }
geeks for geeks

Example 2: In this code, we are going to create two promise constructors.


Output
Promise { <pending> }
geeks for geeks
computer science portal

Example 3: In this example, we will display a value.


Output
5
geeks for geeks
computer science portal
Comment