I've been working with a closure that looks like this:
var Container = (function () {
var variable;
var changeVariable = function () {
variable = 5;
};
return {
variable: variable,
changeVariable: changeVariable
};
})();
Container.changeVariable();
console.log(Container.variable);
Surprisingly, the result is undefined unless I manually set variable to 5 as follows:
Container.variable = 5
This raises some questions in my mind. Why does this happen? What's causing the difference? Is there a correct way for me to handle this situation?