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

189
Vistas
Global Variables and Callback promies in Javascript

I'm fairly new to JavaScript and having some issues with a global scope (I think) with my react app.

from my API I'm receiving a promise containing the .json information of my API request. From what I've read, I need to use a Callback function to access the Data from that API request. I'm trying to save the .json from that request as a global object but I'm having some issues. I've used an alert which can print the .json just fine from within the callback. However, when I try to save it as a global var, Im getting undefined in my main function. How can I ensure that I can access reservationsFromDB from within ReservationList?

var reservationsFromDB;

function receiveResevations (res){

    reservationsFromDB = JSON.stringify(res);

    //Here I get correct .json information
    //window.alert(reservationsFromDB)
}

const ReservationList =  () => {

    api.getReservations().then(res => receiveResevations(res));

    //here i get undefined
    window.alert(reservationsFromDB);

}
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