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

268
Vistas
How to use promise object value in global object?

As shown below, there is a function that pulls data from a specific server using a function that uses a promise object called axios.

const getData = async () => {
try {
    const result = await axios.get(
        "https://b2ef45f8-e166-41d7-bd35-9ad159028fbf.mock.pstmn.io/test"
    );

    const products = result.data.products;

    console.log(products);

    console.log(`status:(${result.status}) sucess to connection`);

    const data = JSON.stringify(products);

    return data;
} catch (err) {
    console.error(err);

    console.log("failed to get result.");

    return err;
}

};

console.log(getData());

it is free to use the value inside the function, When I try to get the value by calling that function in global space, the value Promise { } is first printed to the console, followed by the contents of the function above. I understands that this is because promises are asynchronous. However, I have to use this promise value (data variable) in the global context, so I want to know how to use it in the global context.

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