Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

231
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda