Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

447
Views
JavaScript async/await hace 'indefinido'

Tengo un problema con una función JavaScript que tiene espera asincrónica. Creo esto con el objetivo de aprender la asincronía.

 // 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()

La función num() tiene un comportamiento como una API, debo esperar su respuesta, pero cuando ejecuto todo este código, la primera respuesta es 'indefinido' y luego 'NaN'. no entiendo porque

¿Sabes lo que estoy haciendo mal? ¡Muchas gracias!

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!