The inequality operator should be preferred over negating the equality comparison result
- PREFER_INEQUALITY_OPERATOR
- Code Quality
- Low
- No tags
This rule applies when the logical negation operator is used on the equality comparison result.
The inequality operator (!==
, !=
) gives the same result as applying the negation operator (!
) to the equality (===
, ==
) comparison result. Therefore, it is recommended to use the inequality operator because it is simpler and easier to understand.
Noncompliant Code Example
View with compliant examples side by sideif (!(a === b)) { // PREFER_INEQUALITY_OPERATOR alarm
doSomething(a);
}
Compliant Code Example
View with noncompliant examples side by sideif (a !== b) {
doSomething(a);
}
Version
This rule was introduced in DeepScan 1.25.0.