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

184
Visualizações
Javascript Promise: is the method name for resolve and reject arbitrary?

I am confused on the concepts of Promise, Resolve, Reject, then, catch.

While I know how to write code that works, I want to clarify some questions:

Question 1: Regarding Resolve, Reject, then, catch, Are these methods all introduced together with Promise? Before Promise is introduced to Javascript, does Javascript already have these special methods?

Question 2: Are the method names resolve, reject that are passed as parameters to executor functions in Promise arbitrary? For example:

const executorFunction = (resolve, reject) => {
  if ('1' === '1') {
      resolve('I resolved!');
  } else {
      reject('I rejected!'); 
  }
}
const myFirstPromise = new Promise(executorFunction);

This above code works well, no syntax error or anything. The promise will be in fulfilled state with 'I resolved!' value. But if I do:

const executorFunction = (A, B) => {
  if ('1' === '1') {
      A('I resolved!');
  } else {
      B('I rejected!'); 
  }
}
const myFirstPromise = new Promise(executorFunction);

Would it still work? Will the promise still be in fulfilled state with 'I resolved!' value?

And to make it further, if I swap the method names:

const executorFunction = (reject, resolve) => {
  if ('1' === '1') {
      reject('I resolved!');
  } else {
      resolve('I rejected!'); 
  }
}
const myFirstPromise = new Promise(executorFunction);

Now, would this work? Will the promise still be in fulfilled state with 'I resolved!' value?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

  1. Promise is an object spec that was included with Javascript. Before Promise was included as part of Javascript, the same spec could be built via code.
  2. Executor function is a function. Hence, it doesn't matter what the parameters are called, just their order.
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