Skip to main content

Promise.finally

JUNIOR

Promise.finally

Implement your own version of Promise.prototype.finally.

Requirements:

  • Add a finally method to Promise prototype
  • Execute callback regardless of promise outcome (resolve or reject)
  • Don't modify the resolved/rejected value
  • The callback should not receive any arguments

Example:

Promise.resolve('success')
  .finally(() => console.log('Cleanup'))
  .then(value => console.log(value)); // 'success'

Promise.reject('error')
  .finally(() => console.log('Cleanup'))
  .catch(err => console.log(err)); // 'error'

Examples:

Input 1:{"value":"success"}
Output 1:"success"
Input 2:{"error":"failure"}
Output 2:"failure"

Loading editor...

Run your code to see results

Click the Run button above