Paracetamol.js馃拪| #208: Explica este c贸digo JavaScript

Cristian Fernando - Mar 18 '23 - - Dev Community

Explica este c贸digo JavaScript

Dificultad: Intermedio

const one = () => {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve("one")
    },5000)
  })
}

const two = () => {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      reject(new Error("Error!"))
    }, 2000)
  })
}

const res = () => {
  return Promise.allSettled([one(), two()])
}

res()
  .then(x => console.log(x))
  .catch(err => console.log(err))
Enter fullscreen mode Exit fullscreen mode
  • A.
[
  {status: "fulfilled", value: "one"},
  {status: "rejected", reason: "Error!"}
]
Enter fullscreen mode Exit fullscreen mode

(despu茅s de 5s)

  • B.
[
  {status: "fulfilled", value: "one"},
  {status: "fulfilled", value: "two"}
]
Enter fullscreen mode Exit fullscreen mode

(despu茅s de 5s)

  • C. Promise { <rejected> }
  • D. Ninguna de las anteriores

Respuesta en el primer comentario.


. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .