Valid JS-Dev-101 Dumps shared by EduDump.com for Helping Passing JS-Dev-101 Exam! EduDump.com now offer the newest JS-Dev-101 exam dumps, the EduDump.com JS-Dev-101 exam questions have been updated and answers have been corrected get the newest EduDump.com JS-Dev-101 dumps with Test Engine here:
Refer to the code below: 01 new Promise((resolve, reject) => { 02 const fraction = Math.random(); 03 if (fraction > 0.5) reject('fraction > 0.5, ' + fraction); 04 resolve(fraction); 05 }) 06 .then(() => console.log('resolved')) 07 .catch((error) => console.error(error)) 08 .finally(() => console.log('when am I called?')); When does Promise.finally on line 08 get called?
Correct Answer: D
Comprehensive and Detailed Explanation From Exact Extract JavaScript knowledge: Behavior of Promise.prototype.finally: .finally(handler) registers a callback that runs when the promise is settled, meaning: Either fulfilled (resolved), or rejected. Important points: The finally callback does not receive the promise's value or error (unlike then and catch). It is executed after the promise is settled, but before the resolution value or rejection reason is passed further down the chain. It runs in both success and failure paths. In the given code: The promise may either: Call reject('fraction > 0.5, ' + fraction) if fraction > 0.5, or Call resolve(fraction) otherwise. In both cases: If it resolves, .then(() => console.log('resolved')) runs, and then .finally(...) is executed. If it rejects, .catch((error) => console.error(error)) runs, and then .finally(...) is executed. So .finally runs: Not just "when rejected". Not just "when resolved". But whenever the promise is resolved or rejected. Therefore, the correct choice is: D . When resolved or rejected.