Skip to content

Instantly share code, notes, and snippets.

@DanishSiddiq
Last active March 5, 2021 04:49
Show Gist options
  • Save DanishSiddiq/5345fbe1206296a0e203df92433d24b9 to your computer and use it in GitHub Desktop.
Save DanishSiddiq/5345fbe1206296a0e203df92433d24b9 to your computer and use it in GitHub Desktop.
Early Return Sample
function calculateSomeFormula(param1, param2) {
if (!param1) {
throw new Error('Param1 is not defined');
}
if (isNaN(param1)) {
throw new Error('Param1 is not a number');
}
if (!param2) {
throw new Error('Param2 is not defined');
}
if (isNaN(param2)) {
throw new Error('Param2 is not a number');
}
return (param1 * 2) * (param2 * 3);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment