Skip to content

Instantly share code, notes, and snippets.

@magistrula
Created May 23, 2017 18:52
Show Gist options
  • Save magistrula/8aa1cfe45f395a445182f614b97ad826 to your computer and use it in GitHub Desktop.
Save magistrula/8aa1cfe45f395a445182f614b97ad826 to your computer and use it in GitHub Desktop.
One-line vs Multi-line conditional statements
// one-line, with meaningful logic
function showAlert(text) {
if (!text) console.error('You didn't enter any text!);
alert(text);
}
// one-line, with `return`
function showAlert(text) {
if (!text) return;
alert(text);
}
// one-line with spacing, with meaningful logic
function showAlert(text) {
if (!text) console.error('You didn't enter any text!);
alert(text);
}
// one-line with spacing, with `return`
function showAlert(text) {
if (!text) return;
alert(text);
}
// multi-line, with meaningful logic
function showAlert(text) {
if (!text) {
console.error('You didn't enter any text!);
}
alert(text);
}
// multi-line, with `return`
function showAlert(text) {
if (!text) {
return;
}
alert(text);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment