![]() |
VOOZH | about |
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:
Return Value: Another promise object, in which case the promise gets dynamically inserted into the chain.
Example 1: Creating only one promise constructor.
Promise { <pending> }
geeks for geeksExample 2: In this code, we are going to create two promise constructors.
Promise { <pending> }
geeks for geeks
computer science portalExample 3: In this example, we will display a value.
5 geeks for geeks computer science portal