JavaScript Promise.catch() Explained

JavaScript Logo

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