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

92
Views
JavaScript - Promise parameter

I studying Promise in Javascript.

The two examples look similar, but they produce different results.

The difference is that each parameter of 'then' is used, but I don't know the exact cause.

code #1

const promise = new Promise((resolve, reject) => {
    reject("fail")
    resolve("success");
})
promise.then(
    onfulfilled => console.log(onfulfilled),
    onrejected => console.log(onrejected)
);

result : fail

code #2

const promise = new Promise((resolve, reject) => {
    reject("fail")
    resolve("success");
})
promise.then(
    (onfulfilled, onrejected) => console.log(onfulfilled, onrejected)
);

result : Uncaught (in promise) fail

Thank you.

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

It's how then works. the first parametere is a function with one argument and a second optional function to handle rejection.

in the first code you pass the 2 functions correctly un code 2 you are passing just one function with 2 parameters and so you are not handling the rejection

about 4 years ago · Santiago Gelvez 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!