Skip to content

Merge-Else-If

Documentation Index

Fetch the complete documentation index at: https://docs.sourcery.ai/llms.txt

Use this file to discover all available pages before exploring further.

Merge else clause’s nested if statement into else if

if (response.status == 200) {
return response.data
} else {
if (response.status == 404) {
return "Not Found"
} else if (response.status == 403) {
return "Forbidden"
} else {
return "Error"
}
}
if (response.status == 200) {
return response.data
} else if (response.status == 404) {
return "Not Found"
} else if (response.status == 403) {
return "Forbidden"
} else {
return "Error"
}

Flattening if statements nested within else clauses generates code that is easier to read and expand upon.