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

236
Views
What is the parameter passed to the callback function of a promise in this example?

I'm following an example online:

const jeffBuysCake3 = cakeType => {
  return new Promise((resolve, reject) => {
    setTimeout(()=> {
      if (cakeType
 === 'black forest') {
        resolve('black forest cake!') //Callback function
      } else {
        reject('No cake 😢') //Callback function
      }
    }, 1000)
  })
}

console.log(jeffBuysCake3('black forest').then(cake => console.log(cake)).catch(nocake => console.log(nocake)))

This returns black forest cake!

The part I don't understand is cake => console.log(cake)

What is cake in this example?

I understand that passing 'black forest' represents the parameter cakeType.

However It's not clear to me what 'cake' is.

Does cake = resolve?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Cake means the result of the successfully called promise, in this example they probably want to mean the cake result, and the cake result is a "black forest".

You could write it like this

jeffBuysCake3('black forest')
.then(result => console.log(result))
.catch(error => console.log(error))

and the result is going to be "black forest cake", if the promise function was like this

const jeffBuysCake3 = cakeType => {
  return new Promise((resolve, reject) => {
    setTimeout(()=> {
      if (cakeType
 === 'black forest') {
        resolve('Strawberry cake !') //Callback function
      } else {
        reject('No cake for you today') //Callback function
      }
    }, 1000)
  })
}

the result is going to be "Strawberry Cake !", while if there was an error it would print out "No cake for you today".

In case you don't know how promises work, when we supply .then it means if the promise resolved (successfully) then give me back the result. If it couldn't be resolved, then catch the error which then we use .catch.

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!