include::../why-general.adoc[]

Note that functions in JavaScript are first-class citizens. This means that they possess the same attributes as variables, including the ability to shadow other variables and, conversely, be shadowed by them. 

=== Noncompliant code example

The example below shows the typical situations in which shadowing can occur.

[source,javascript]
----
function outer(items) {
  var counter = 0;

  function inner(items) { // Noncompliant: the parameter "items" is shadowed.
    var counter = counter + 1; // Noncompliant: the outer "counter" is shadowed.
  }

  inner(items);

  return counter; // returns 0
}

function search(items, match) { // Noncompliant: the function "match" (below) is shadowed.
  // ...
}

function match(value, key) {
  // ...
}
----

== Resources

=== Related rules

* S2814 - Variables and functions should not be redeclared

include::../rspecator.adoc[]
