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

449
Visualizações
JavaScript async/await makes 'undefined'

I have a problem with a JavaScript function that it has async await. I create this with the goal of learning asynchrony.

   // function that just solve an addition
function addition(num1, num2){        
    let sum = num1 + num2
    return sum
    }

    // I treat this function as an api
function num(value=3){
    setTimeout( function (){
        let num = value;
        return num
    }, 3000)
}

    // I put an async/await for waiting the response of 'num' function
const Exercise = async() => {
    const num2 = await num(2)
    console.log(addition(3,num2))
}
    
Exercise()

The num() function has a behaviour as an API what I've to wait it response, but when I run all of this code the first response is 'undefined' and then 'NaN'. I don't understand why.

Do you know what I'm doing wrong? Thanks a lot!

about 4 years ago · Juan Pablo Isaza
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