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

120
Views
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 answers
Answer question

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