Search code examples
javascriptes6-promise

What is the difference between having resolve, reject in a new Promise and not having it?


Is this code a Promise ?

 let fetchData = fetch("https://jsonplaceholder.typicode.com/users")
  .then(res => res.json())
  .then(data => {
    console.log(data[0].name)
  })
  .catch(err => {
    console.log('Opps! something went wrong :(')
  })

What is the difference between having a Promise like this and create a new Promise which has resolve and reject to invoke .then and .catch blocks ?


Solution

  • fetch function is returning a Promise object that's why you are able to use .then and .catch blocks.