All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.javascript.AssignmentWithinCondition.html Maven / Gradle / Ivy

Doing an assignment in the condition part of a 'if', 'while' or 'for' statement is highly not recommended for the two following reasons :

  • The assignment is perhaps a bug as the '=' operator might have been used in place of the '==' operator
  • If this is not a bug, this is highly error prone as another developer might read '==' instead of '=' while trying to maintain the source code
if (dayNumber = getClickedDayNumber(dayInfo))   // BUG
{
    alert("day number found : " + dayNumber);
}

If you really want to do the assignment in place, then better to do an explicit comparison as well :

if ((value = someFunction()) === true) { // OK
  // ...
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy