Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
const myPromise = () => {
  return new Promise((resolve, reject) => {
    // return 1 after the promise is resolved
    setTimeout(() => resolve(1), 2000)
  })
}
myPromise().then((result) => {
  console.log(result)
  return result + 1
}).then((result) => {
  console.log(result)
  return result + 1
}).then((result) => {
  throw new Error('FAILED HERE') // <- simulate an error in the promise chain
  console.log(result)
  return result + 1
}).catch((e) => {
  // catch error that occurs anywhere
  // the promise chain
  console.log('an error occurred')
  console.log(e)
})
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x