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