CodeQL documentation

Ignoring result from pure array method

ID: js/ignore-array-result
Kind: problem
Security severity: 
Severity: warning
Precision: high
Tags:
   - quality
   - reliability
   - correctness
Query suites:
   - javascript-security-and-quality.qls

Click to see the query in the CodeQL repository

The concat, join and slice methods are pure and do not modify any of the inputs or the array the method is called on. It is therefore generally an error to ignore the return value from a call to one of these methods.

Recommendation

Use the returned value from the calls to concat, join or slice.

Example

A function extend is defined in the following example. The function uses the concat method to add elements to the arr array. However, the extend function has no effect as the return value from concat is ignored:

var arr = [1,2,3];

function extend(others) {
	arr.concat(others);
}

Assigning the returned value from the call to concat to the arr variable fixes the error:

var arr = [1,2,3];

function extend(others) {
	arr = arr.concat(others);
}

References

  • © GitHub, Inc.
  • Terms
  • Privacy
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy