Lets assume modulex and moduley both are not declared at all.
Now consider two scenarios:
var modulex = modulesx || {}; // This line of code works fine
moduley = moduley || {}; // but this code throws error saying moduley is undefined.
Again,
var modulex = moduley || {}; // This also throws error saying moduley is undefined.
Please elaborate on this one.
In JavaScript, variable declarations are hoisted. This code:
Is actually interpreted like this:
In your second example,
moduleyjust isn’t defined, which is exactly what your error says.