2

I am using more and more javascript in my work and wonders what is good practice when it comes to the examples below.

function foo(){
    //do stuf
    var bar = foo2();
    //do stuf

    function foo2(){
        //do stuf
        return aValue;
    }
}

No other functions needs to know about foo2() which is why I sometimes hides it in foo(). The downside is that I think that readability of foo() is lost and it could be harder to locate foo2(). Is this good practice or should I rather do it like this:

function foo(){
    //do stuf
    var bar = foo2();
    //do stuf
}
function foo2(){
    //do stuf
    return aValue;
}
Mikael Holmgren
  • 2,466
  • 1
  • 18
  • 27
  • 2
    With modern JavaScript engines, this is basically a matter of preference, coding style, etc. There is no "correct" answer. There are technical advantages and disadvantages, but the choice on those trade-offs is up to you and probably varies on a case-by-case basis. – T.J. Crowder Aug 29 '13 at 08:35

0 Answers0