
Promise.catch() – Handles promise rejection (errors). Always pair with `.then()` or use `.catch()` alone for error handling.
๐ Syntax
promise.catch(error => {
// handle error
});
๐งช Example
fetch('/bad-url')
.then(res => res.json())
.catch(err => console.error('Error:', err));
Comments
Post a Comment