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

198
Visualizações
return a boolean value with a promise

here is my code:

const executorFunction = (resolve, reject) => {

<script>
      
if (  1==1){

    resolve(true);
   
}
else{
    resolve(false);
}

    }




const myFirstPromise = new Promise(executorFunction);


console.log(myFirstPromise);


        </script>

Here is the output of my code:

Promise {<fulfilled>: true}
[[Prototype]]: Promise
[[PromiseState]]: "fulfilled"
[[PromiseResult]]: true

I want the boolean value true in the variable myFirstPromise

and i want this output:

true

What is the solution please?

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

0

You need to use then. Also the script tag inside the executorFunction function does not make any sense

const executorFunction = (resolve, reject) => {
  if (1 === 1) {
   resolve(true);
  } else {
    resolve(false);
  }

}
const myFirstPromise = new Promise(executorFunction);

myFirstPromise.then(d => console.log(d))

how I can get the boolean value true in a variable out of the function

That may not be possible directly with Promise, instead you can use async function. Internally this also returns a Promise

function executorFunction() {
  return 1 ? true : false;
}

async function getVal() {
  const val = await executorFunction();
  console.log(val)
}

getVal()

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