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

121
Visualizações
Using side effects in control flow

Is it considered bad practice to have side effects in an if statement? For example, something like this:

'use strict';
let a = 2;
if ( a++ > 2) {
    // ...
}

Or:

'use strict';
let a = 2;
if ( a++ > 2, a) {
    // ...
}

Or:

'use strict';
let a = 2;
if ( ++a > 2 && a++) {
    // ...
}

If so, why would that be frowned upon, and what might be a better approach?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Yes, it is considered as a bad practice by some (me included). There are linter rules to avoid this convention.

Why?

Because it's less readable. You want a single instruction to perform a single action. a++ vs ++a not only does something in expression (which can already be considered clumsy), but also doesn't seem to be easiest to read. I always need to think for a moment whether the value returned is a or a + 1.

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