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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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
returnstatement at the end of a function. Seems clearer to me.