When i pick my project, i do write it with functional programming so, Is it need to end your function code with a return?
For further actions, you may consider blocking this person and/or reporting abuse
When i pick my project, i do write it with functional programming so, Is it need to end your function code with a return?
For further actions, you may consider blocking this person and/or reporting abuse
Paul -
花间酒 -
Roseanne -
Mr. Algorithm -
Top comments (4)
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.
Some programming languages use automatic implicit return, like Nim and Rust.
In Javascript, we also use functions as a closure. It's like a procedure rather than a function and I usually don't return things.