Skip to content

Instantly share code, notes, and snippets.

@zzdjk6
Last active May 17, 2020 03:48
Show Gist options
  • Save zzdjk6/7c34330a06dfb78d6bd301f9faafa21a to your computer and use it in GitHub Desktop.
Save zzdjk6/7c34330a06dfb78d6bd301f9faafa21a to your computer and use it in GitHub Desktop.
Less Readable #EarlyReturn
function doSomething(user, data) {
if (hasPermission(user)) {
if (isNetworkAvailable()) {
if (isValid(data)) {
sendToServer(user, data);
} else {
throw new DataInvalidError();
}
} else {
saveInQueue(user, data);
}
} else {
throw new PermissionDeniedError();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment