title: Set window variable value in by a function
body: <p>I want to set window.userName variable value by the function, but I fail:</p>
  
  <pre><code>function changeName(variable) {
   variable = "Bill";
  }
  
  changeName( window.userName );
  
  console.log( window.userName ); // outputs undefined
  </code></pre>
  
  <p>How could I pass the window.userName variable reference to the function or what else you would suggest to do with it?</p>
  
  <p>Any help would be highly appreciated. Thanks!</p>
  
  <p>Here is the code snippet that shows you main idea of the action:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var data = [{
    "name": "Bill",
    "location": {
      "latitude": "12.4124",
      "human_address": {
        "address": "Blabla St. 13",
        "city": "Moscow"
      },
      "longitude" : "51.2512"
    }
  },
  {
    "name": "James",
    "location": {
      "human_address": {
        "city": "Moscow"
      }
    }
  }];
  
  var allColumns = {};
  
  function loopInto(targetObj, obj) {
    for (var k in obj) {
      if (!(k in targetObj)) {
        targetObj[k] = true;
      }
      if (typeof obj[k] == "object") {
        if (targetObj[k] == true)
          targetObj[k] = {};
        loopInto(targetObj[k], obj[k]);
      }
    }
  }
  
  for (i=0; i&lt;data.length; i++) {
    for (var k in data[i]) {
      if (!(k in allColumns)) {
        allColumns[k] = true;
      }
      if (typeof data[i][k] == "object") {
        if (allColumns[k] == true)
          allColumns[k] = {};
        loopInto(allColumns[k], data[i][k]);
      }
    }
  }
  
  console.log( allColumns );</code></pre>
  </div>
  </div>
  </p>
  
  <p>As you can see, I am able to pass <code>allColumns[k]</code> object by reference and then change its value through the <code>loopInto</code> function. But why am I unable to do the same with e.g. <code>window.allColumns</code> variable? If you try replace <code>allColumns</code> with <code>window.allColumns</code> it fails.</p>