Defining var with same name (MODULE) shoudn't overwrite (remove) the upper module.
Yes, it should.
The global scope (or the function if you are inside a function) is scanned for var
statements. Since you have two identical ones, the second one is ignored. MODULE
is created in the global scope.
Then you run a function and then assign its return value to the MODULE
.
Then you run another function, passing the current value of MODULE
as an argument to it, then you assign the return value to MODULE
.
A reference to the object created at var my = {}
still exists in the scope of the second function, but the only reference to it from the global scope has been overwritten.