Global variables in JavaScript strict mode Global variables in JavaScript strict mode angularjs angularjs

Global variables in JavaScript strict mode


The faulty assumption is that in strict mode all global variables are disallowed. Actually only undefined global variables throw an error. (In fact you basically couldn't do anything at all if you couldn't use any global variables. There has to be at least something in the global scope.)

For example:

"use strict";var a = "foo";var b;(function() {    a = "bar";  // this is ok, initialized earlier    b = "baz";  // this is also ok, defined earlier    c = "qux";  // this is not, creating an implicit global})();

Using variables a or b is not a problem, but c will throw an error. There should be no problems using the eventApp variable in your example.


You don't have to reference eventsApp because angular will hold a reference to the object by the name 'eventsApp' that you are using to define the module.

So, in all other files you can just use:

angular.module('eventsApp');

To get access to the module.