title: How to access a variable from outer scope in JavaScript
body: <p>In the example bellow, I am trying to access the <code>x</code> that is in the function outer.</p>
  
  <p>I was expecting to get 20 as an output, however the output is <code>undefined</code>.</p>
  
  <p>Can someone explain why is that happening, and is there a way to access the outer x?</p>
  
  <pre><code>var x = 10;
  function outer() {
      var x = 20;
      function inner() {
          var x = 30;
          function printX() {
              console.log(outer.x);
          }
          printX();
      }
      inner();
  }
  outer();
  </code></pre>