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

348
Vistas
Cannot access the value outside of Promise 'then' method

I'm using asynchronous functions with Promise in order to make use of Google Sheets API. Everything is working fine except for one thing: I'm not able to access the value returned by the API outside of 'then'. Inside then, 'content' is printing the right value. Here is the relevant part of the code:

var val = selectPayloadContent(serviceName)
  .then(content => console.log("Outputting content: ", content))
  .catch(error => console.log(error));

console.log("Outputting content outside: ", val);

val.then(function(result) {
  console.log("Val: ", result);
});

I realize this is a common issue and I've gone through a lot of questions and different articles. However, I can't seem to resolve this problem. Please note:

  • 'val' in the console log is showing Promise {pending}.
    PromiseState is fulfilled and PromiseResult is undefined.
  • 'result' in the console log is showing undefined

Any kind of help will be really appreciated. Thanks.

about 4 years ago · Juan Pablo Isaza
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