What does the finally() method do in a promise?

What does the finally() method do in a promise?

a) Executes a block of code after the promise is settled, regardless of the result
b) Executes a block of code only if the promise is resolved
c) Executes a block of code only if the promise is rejected
d) Cancels the promise

Answer:

a) Executes a block of code after the promise is settled, regardless of the result

Explanation:

The finally() method is called after a promise is either resolved or rejected. It is often used for cleanup actions that need to happen regardless of the outcome.

Reference:

JavaScript MCQ (Multiple-Choice Questions)

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top