Consider a function that fetches user information from an API. If the API call fails, you want to log an error message and then continue the execution of the function without throwing an exception to the outer scope. Which Promise method should you use to achieve this?
- Promise.catch()
- Promise.finally()
- Promise.reject()
- Promise.resolve()
You should use Promise.catch() to handle errors in a Promise. This method allows you to specify a callback function that will be called when the Promise is rejected, allowing you to log an error message and gracefully continue execution without propagating the error to the outer scope.
Loading...
Related Quiz
- The shift() method will return _______ when it is used on an empty array.
- If a variable is declared inside a block using the let keyword, it is not accessible _________ that block.
- Which comparison operator performs type coercion if the operands are of different types?
- What is the main difference between function declaration and function expression in JavaScript?
- Which property is used to change the text content of a selected element?