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

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

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 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