DEV Community

Discussion on: Should i end my function code, with a return?

Collapse
 
sargalias profile image
Spyros Argalias

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.

Collapse
 
wallwrecker profile image
wallWrecker

Thank you.