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

196
Views
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 answers
Answer question

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 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!