Complete the code to create a new Promise.
const myPromise = new [1]((resolve, reject) => { resolve('Done'); });
Promises in JavaScript are created using the Promise constructor.
Complete the code to handle a resolved Promise.
myPromise.[1](result => {
console.log(result);
});The then method is used to handle the result when a Promise is resolved.
Fix the error in the code to handle Promise rejection.
myPromise.then(result => {
console.log(result);
}).[1](error => {
console.error(error);
});The catch method is used to handle errors when a Promise is rejected.
Fill both blanks to create a Promise that rejects on error.
const errorPromise = new Promise(([1], [2]) => { [1]('Success'); [2]('Error occurred'); });
The first parameter is resolve to handle success, the second is reject to handle errors.
Fill all three blanks to create a Promise and handle both success and failure.
const promise = new Promise(([1], [2]) => { if(true) { [1]('Done'); } else { [2]('Failed'); } }); promise.[3](message => console.log(message)).catch(error => console.error(error));
Use resolve and reject in the Promise constructor, and then to handle success.
