title: Setting object values in JavaScript
body: <p>I've tried my best to work this out, now I'm stuck, why does the fourth alert return undefined?</p>
  
  <pre><code>function buttonClick()
  {
    var myTest = function()
    {
      var _setDirectlyInside = "So far so good...";
      var _setInFunctionCalledInside;
      var _setInFunctionCalledFromOutside;
  
      (function(){
        _setInFunctionCalledInside = "This would indicate scope isn't the problem?";
      })();
  
      return {
        basic : "Easy stuff",
        setDirectlyInside : _setDirectlyInside,
        setInFunctionCalledInside : _setInFunctionCalledInside,
        functionCallFromOutside : function(){
          _setInFunctionCalledFromOutside = "Why does this come back as undefined?";
        },
        setInFunctionCalledFromOutside : _setInFunctionCalledFromOutside
      }
    };
  
    var test = myTest();
  
    alert(test.basic); // Returns "Easy stuff"
    alert(test.setDirectlyInside); // Returns "So far so good..."
    alert(test.setInFunctionCalledInside); // Returns "This would indicate scope isn't the problem?"
  
    test.functionCallFromOutside();
    alert(test.setInFunctionCalledFromOutside); // Broken, returns undefined
  }
  </code></pre>
  
  <p>Resolution:</p>
  
  <pre><code>setInFunctionCalledFromOutside : _setInFunctionCalledFromOutside, // Won't work
  setInFunctionCalledFromOutsideGetter : function(){
      return _setInFunctionCalledFromOutside; // Will work
  }
  
  ...
  
  alert(test.setInFunctionCalledFromOutside); // Broken, returns undefined
  alert(test.setInFunctionCalledFromOutsideGetter()); // Now works
  </code></pre>