title: When to use internal function and when not to?
body: <p>I am using more and more javascript in my work and wonders what is good practice when it comes to the examples below.</p>
  
  <pre><code>function foo(){
      //do stuf
      var bar = foo2();
      //do stuf
  
      function foo2(){
          //do stuf
          return aValue;
      }
  }
  </code></pre>
  
  <p>No other functions needs to know about <code>foo2()</code> which is why I sometimes hides it in <code>foo()</code>. The downside is that I think that readability of <code>foo()</code> is lost and it could be harder to locate <code>foo2()</code>. Is this good practice or should I rather do it like this:</p>
  
  <pre><code>function foo(){
      //do stuf
      var bar = foo2();
      //do stuf
  }
  function foo2(){
      //do stuf
      return aValue;
  }
  </code></pre>