single return vs multiple returns
- Dominant language
- JavaScript
- Stars
- 148k
- Forks
- 26.6k
- PR merge metrics
- No merged PRs in 30d
Description
I see some examples of multiple returns but don't see any guidelines defined that say it explicitly.
Is there a preference between a single return where a variable is assigned the output value vs just having multiple return statements?
```
function isGood(battery) {
if (battery.charge) {
return true;
}
if (battery.cycles < 10) {
return true;
}
return false;
}
```
vs.
```
function isGood(battery) {
let out = false;
if (battery.charge) {
out = true;
}
if (battery.cycles < 10) {
out = true;
}
return out;
}
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Review the existing style-guide examples and the 22-comment discussion to understand the unresolved preference between multiple returns and a single final return. Done means reaching a documented decision and adding a clear guideline to the relevant style-guide section, with examples covering both forms if needed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100