Prefer
>
for comparing collection sizes with 0. >= 0
always evaluates to true 54 }
55
56 let ports = Registry.featureSet.getComponentPorts(cleanparamdata, this.__type);
57 if (ports !== undefined && ports.length >= 0 && ports !== null) { 58 for (let i in ports) {
59 this.setPort(ports[i].label, ports[i]);
60 }
Description
Avoid using >= 0
and < 0
when comparing container sizes.
When comparing collection sizes (array.length
, set.size
) with 0
, it is recommended to use the >
and ==
operators over the >=
and <
operators.
Collections like arrays and sets always have a minimum size of 0.
Therefore, >= 0
always evaluates to true
and < 0
always evaluates to false
.
Bad Practice
if (myArray.length >= 0) {
// this block *always* executes
}
if (mySet.size < 0) {
// this block *never* executes
}
Recommended
if (myArray.length > 0) {
// block executes only if array is not empty
}
if (mySet.size == 0) {
// block executes only if set is empty
}