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

144
Vistas
Why can't I single-line object properties from objects returned from async functions?

I am wanting to use an object that is returned from an asynchronous function.

async function myPromise() {
  console.log("Single-line", await getUsers().quote);
  let users = await getUsers();
  console.log("Multi-line", users.quote);
}

async function getUsers() {
  return await new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve({
        name: "Jeff",
        id: 1,
        quote: "Hello world!"
      });
    }, 1000)
  });
}

myPromise();

Why do I have to assign the result of an asynchronous function to a variable before I can use the properties stored within the object that was returned?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The property accessor has precedence over the await operator, so you need to add parentheses:

(await getUsers()).quote
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