>
for comparing collection sizes with 0. >= 0
always evaluates to true 57 const cleanparamdata = this._params.toMap();
58 if ((mint !== "" && mint !== "TEXT") || mint === null) {
59 const ports = ComponentAPI.getComponentPorts(cleanparamdata, mint);
60 if (ports != undefined && ports.length >= 0 && ports !== null) { 61 for (const port of ports) {
62 this.setPort(port.label, port);
63 }
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
.
if (myArray.length >= 0) {
// this block *always* executes
}
if (mySet.size < 0) {
// this block *never* executes
}
if (myArray.length > 0) {
// block executes only if array is not empty
}
if (mySet.size == 0) {
// block executes only if set is empty
}