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

91
Vistas
javascript new Function with await doesn't seem to work but with no error message

syncTest works, await asyncTest doesn't but there's no error message, so I can't see how to fix this ?

function syncTest(a) {
  return a;
}

async function asyncTest(a) {
  return a;
}

async function test() {
  let value1 = new Function(
    `return syncTest("123");`
  )();
  console.log(value1);

try {
  let value2 = new Function(
    `return await asyncTest("123");`
  )();
  console.log(value2);
}
catch(e) {
  console.log(error.message);
}

}

test();

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

0

2 possible problems:

Using await most likely means the function will return a Promise, not plain text. Learn about it here, you won't regret it.

Second, the "new Function" command you are using is quite odd, and most likely isn't asynchronous in this case. The await keyword only works in asynchronous functions, E.g. (async()=>{}) is an asynchronous function.

Please take this all with a grain of salt, as I am unable to test this at the moment. Just some words of wisdom! ✨

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