NathanP
NathanP

Reputation: 49

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 ?

Upvotes: 0

Views: 66

Answers (1)

akshay karande
akshay karande

Reputation: 158

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

Upvotes: 2

Related Questions