Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

90
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda