Rule proposal: Prefer `else`
See original GitHub issueIn following case, use else
is more readable than continue
and return
, but only the else
block is small.
Fail
for (const element of array) {
if (foo) {
bar();
continue;
}
baz();
}
function a() {
if (foo) {
bar();
return;
}
baz();
}
Pass
for (const element of array) {
if (foo) {
bar();
} else {
baz();
}
}
function a() {
if (foo) {
bar();
} else {
baz();
}
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Proposed rule: Private Fund Advisers - SEC.gov
We propose to require registered investment advisers to private funds to provide transparency to their investors regarding the full cost of ...
Read more >Basic components of a proposal | Foundation Relations
Demonstrate your knowledge of the field. Provide convincing evidence that what you are proposing does not duplicate other work. Replication of someone else's...
Read more >26 Signs You Should Propose ASAP - WeddingWire
It may seem like a small grammatical change, but it's actually huge. ... in-law relationship (and if they haven't met yet, get on...
Read more >DO NOT Interrupt a Disney Proposal Like This Woman Did
A Guest decided to get down on one knee and propose to his love, ... something wonderful happen for someone else — like...
Read more >Wikipedia:Perennial proposals
Consensus can change, and some proposals that remained on this page for a long time have finally been proposed in a way that...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Can you elaborate on why you think it’s more readable? Because I personally find the
continue
/return
version more readable, for the same reasons I prefer early-returns: less nesting.I agree this case should do early exit.