var a = 1;
function myFunction() {
++a;
return true;
}
// Alert pops up.
if (myFunction() && a === 2) {
alert("Hello, world!")
}
// Alert does not pop up.
if (a === 3 && myFunction()) {
alert("Hello, universe!")
}
myFunction increments a variable and returns something. If I use a function like that in an if statement that contains the variable which it increments, the condition would be order-dependent.
Is it good or bad practice to do this, and why?
Aucun commentaire:
Enregistrer un commentaire