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 .