function f() {
return f1();
function f1() {
return 5;
}
}
f(); // returns 5
Why this works? What are benefits of declaration local functions after return
? Is this good practice?
It works because function declarations are all evaluated on a first pass by the interpreter, so you could place them all at the end of the function if you want, and they will work as though they were at the top.
No benefits. Just a preference. I prefer to have the return
statement at the end of a function. Seems clearer to me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With