Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

56
Views
Javascript promete curiosidad

Cuando llamo a esta promesa, la salida no coincide con la secuencia de llamadas a funciones. El .then viene antes que el .catch , aunque la promesa con .then estaba siendo llamada después. ¿Cuál es la razón para eso?

 const verifier = (a, b) => new Promise((resolve, reject) => (a > b ? resolve(true) : reject(false))); verifier(3, 4) .then((response) => console.log("response: ", response)) .catch((error) => console.log("error: ", error)); verifier(5, 4) .then((response) => console.log("response: ", response)) .catch((error) => console.log("error: ", error));

producción

 node promises.js response: true error: false
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

 Promise.resolve() .then(() => console.log('a1')) .then(() => console.log('a2')) .then(() => console.log('a3')) Promise.resolve() .then(() => console.log('b1')) .then(() => console.log('b2')) .then(() => console.log('b3'))

En lugar de la salida a1, a2, a3, b1, b2, b3, verá a1, b1, a2, b2, a3, b3 por la misma razón: cada vez que devuelve una promesa y va al final del bucle de eventos cola. Entonces podemos ver esta "carrera de promesa". Lo mismo ocurre cuando hay algunas promesas anidadas.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!