When a non-existent variable is referenced a ReferenceError is raised.

Due to the dynamic nature of JavaScript this can happen in a number of scenarios:

This rule does not raise issues on global variables which are defined with sonar.javascript.globals and sonar.javascript.environments properties.

Noncompliant Code Example

var john = {
  firstName: "john",
  show: function() { console.log(firstName); } // Noncompliant: firstName is not defined
}
john.show();

Compliant Solution

var john = {
  firstName: "john",
  show: function() { console.log(this.firstName); }
}
john.show();