In JavaScript, PL/SQL and some other languages, functions can be nested, i.e. declared within another function. This could be used to break a large function into smaller pieces, but keep those pieces within the context of the larger function.function doTooMuch() {    function doSomething () {       ...    }    function doSomethingElse() {       ...    }    function doYetAnotherThing() {       ...    }    // doTooMuch body    doSomething();    doSomethingElse();    doYetAnotherThing();}In some cases, when those smaller functions do not use local variables of the larger function, this could easily changed to a version where all functions are unnested.function doSomething () {   ...}function doSomethingElse() {   ...}function doYetAnotherThing() {   ...}function doTooMuch() {    doSomething();    doSomethingElse();    doYetAnotherThing();}Assuming that those nested functions are not to be used anywhere else, is it better to keep them within the context of the large function or is it bad because this is exactly what makes the large function, well, large?
Should I nest functions in languages that allow me to do that or should I rather avoid it?
javascript;coding style
It is a matter of opinion, but I would avoid nesting functions unless it was actually a necessary and deliberate part of your design.When you nest functions, in most languages, you end up with some sort of mechanical effect.  The most common, and interesting, is to close over the lexical scope of a variable that can be used inside the body, but others (eg: visibility of the function) also show up some of the time.Those are typically awesome tools, when used right - but they are complex tools, because they can result in non-local or non-obvious effects when you first glance at the code.If you don't use them, many people will read the code and not see anything doing that - so will assume they missed it, and look again, trying to work out why you did it that way, and not in a separate scope.You also risk that future programmers will deliberately or even accidentally close over something they didn't intend to, by not noticing the risk right there.Finally, if your function declaration declares a named function outside the scope of the enclosing function, just avoid it.  That is super confusing to everyone.As to the final note: because individual functions help delimit code, nesting functions is less troublesome than a single giant function, but ultimately it does mean reading a lot more code to understand doTooMuch() - especially if you can hide code between the nested function declarations, or need to check that nobody did.