Skip to content

Instantly share code, notes, and snippets.

@Amir-A-M
Last active August 21, 2022 12:48
Show Gist options
  • Select an option

  • Save Amir-A-M/3f43cedaaa57472150e234e121f097cd to your computer and use it in GitHub Desktop.

Select an option

Save Amir-A-M/3f43cedaaa57472150e234e121f097cd to your computer and use it in GitHub Desktop.
confusing code return early pattern
function returnStuff(argument1, argument2) {
if (argument1.isValid()) {
if (argument2.isValid()) {
const otherVal1 = doSomeStuff(argument1, argument2);
if (otherVal1.isValid()) {
const otherVal2 = doAnotherStuff(otherVal1);
if (otherVal2.isValid()) {
return "Stuff";
} else {
throw new Exception();
}
} else {
throw new Exception();
}
} else {
throw new Exception();
}
} else {
throw new Exception();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment