A collection is a data structure that holds multiple values, such as an array or a map. If a collection is declared and populated, but its values
are never read anywhere in the code, it can be considered unused code. This can be due to some refactoring, copy-pasting, or typing errors.
Unused collections can waste memory usage and slow down the application’s performance. Additionally, they can make the code harder to read and
understand, especially for other developers working on the same codebase.
function getLength(a, b, c) {
const strings = []; // Noncompliant: Array is declared and populated but never read
strings.push(a);
strings.push(b);
strings.push(c);
return a.length + b.length + c.length;
}
Remove unused collections so that the application can run faster and more smoothly. The code becomes cleaner and more efficient, making it easier
to read, understand, and maintain.
function getLength(a, b, c) {
return a.length + b.length + c.length;
}