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

171
Views
Evaling async function definitions

I work on an IDE for Javascript that lets developers evaluate their code. In a modern Chrome console, I can run:

eval(`try{function foo3(){console.log("Hi")}} catch(err){console.log(err)}`)

and foo3 will be defined and called fine. I can also run:

eval(`async function foo4(){console.log("Hi")}`)

and foo4 will be defined and called fine. But when I run:

eval(`try{async function foo5(){console.log("Hi")}} catch(err) {console.log(err)}`)

I get no error, but foo5 is not defined. Note that the difference between example 1 and example 3 is just "async" before "function". I would like foo5 to be defined. Clues greatly appreciated.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Well, you could invert your code slightly, to include the try/catch block, within your async function to get it going.

eval(`async function foo5() {try {console.log("Hi")} catch (err) { console.log(err)}}`);

foo5();

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