Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

102
Visualizações
Where is rejected property stored for a Promise in Javascript?

In the following code, the output clearly shows that rejected is within the created promise1 object. Yet when I look at MDN, there is no property indicating whether a promise is resolved or rejected. How does the program know whether a promise is accepted? Where is this information stored?

const promise1 = new Promise((resolve, reject) => {
  throw 'Uh-oh!';
});

console.log(promise1); //Promise { <rejected> 'Uh-oh!' }

promise1.catch((error) => {
  console.error(error);
});
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

If I correctly get the question, you ask about the cases upon which JS itself rejects the promise. A promise is rejected when an error is returned from the callback function. In general case you (the programmer) define the conditions which mean success or error according to the code business. Based on what you need, you can either throw or reject the promise and this Q&A looks helpful. But when a promise is gonna be used with a specific purpose, this behavior seems more clear, say when you use JS fetch api, there are solid situations in which the promise would be rejected.i.e. network disconnections or CORS errors. Here you can find a more detailed reply. These situations are those which are not biased towards any data transfer protocol such as HTTP. Finally, here, you can find a pretty well explained pattern for designing your promise workflow.

about 4 years ago · Juan Pablo Isaza Relatório

0

There is no public API to check the Promise state, so there is no property that you could check.

Given the impossibility, you can try to do it on your own with any of these solutions:

https://ourcodeworld.com/articles/read/317/how-to-check-if-a-javascript-promise-has-been-fulfilled-rejected-or-resolved

https://github.com/nodejs/node/issues/40054#issuecomment-917641057

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda