Front end developer specialising in JavaScript and React. Experienced in all aspects of modern front end development. Passionate about making accessible, secure and performant software.
There isn't really a short answer to this question. It depends on what the purpose of your function is, which depends on how you're structuring your project, which also depends on whether using primarily an FP style or an OOP style in your project. So it depends.
In functional programming, most functions will be pure, so they generally return something, so they should end with return something. Functions with side effects probably won't return something. This also follows the command-query separation principle.
But if you're asking whether you should return in a function or just let it implicitly return undefined on its own, then it's more common to let the function return undefined implicitly and not use a return statement.
There isn't really a short answer to this question. It depends on what the purpose of your function is, which depends on how you're structuring your project, which also depends on whether using primarily an FP style or an OOP style in your project. So it depends.
In functional programming, most functions will be pure, so they generally return something, so they should end with
return something
. Functions with side effects probably won't return something. This also follows the command-query separation principle.But if you're asking whether you should
return
in a function or just let it implicitly returnundefined
on its own, then it's more common to let the function returnundefined
implicitly and not use a return statement.Thank you.