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

251
Views
What is the difference between these two async ternary statements?

Can someone help me understand the difference if any between these two below ternary statements?

const variables = await (conditional ? asyncFunctionOne() : asyncFunctionTwo());
    
const variables = conditional ? await asyncFunctionOne() : await asyncFunctionTwo();

At first glance, these both do the same thing, but some part of me thinks these do not execute in the same order.

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

0

There would be a small difference if this were a function call:

const variables = doSomething(conditional ? functionOne() : functionTwo());
    
const variables = conditional ? doSomething(functionOne()) : doSomething(asyncFunctionTwo());

const temp = conditional ? functionOne() : asyncFunctionTwo();
const variables = doSomething(temp);

These may look equivalent on a first glance, but are not if the code in conditional or even inside functionOne/functionTwo does change the doSomething variable.

However, await is not a function but syntax, its meaning is determined when parsing and compiling the code, not when evaluating it and resolving a variable. So the two lines in your question are absolutely equivalent.

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!