== Why is this an issue?

Any variable or function declared in the global scope implicitly becomes attached to the global object (the ``++window++`` object in a browser environment). To make it explicit this variable or function should be a property of ``++window++``. When it is meant to be used just locally, it should be declared with the ``++const++`` or ``++let++`` keywords (since ECMAScript 2015) or within an Immediately-Invoked Function Expression (IIFE).


This rule should not be activated when modules are used.


=== Noncompliant code example

[source,javascript]
----
var myVar = 42;       // Noncompliant
function myFunc() { } // Noncompliant
----


=== Compliant solution

[source,javascript]
----
window.myVar = 42;
window.myFunc = function() { };
----
or

[source,javascript]
----
let myVar = 42;
let myFunc = function() { }
----
or 

[source,javascript]
----
// IIFE
(function() {
  var myVar = 42;
  function myFunc() { }
})();
----



ifdef::env-github,rspecator-view[]

'''
== Implementation Specification
(visible only on this page)

=== Message

Define this declaration in a local scope or bind explicitly the property to the global object.


=== Highlighting

variable or function


'''
== Comments And Links
(visible only on this page)

=== relates to: S806

=== relates to: S2703

endif::env-github,rspecator-view[]
