Created
May 23, 2017 18:52
-
-
Save magistrula/8aa1cfe45f395a445182f614b97ad826 to your computer and use it in GitHub Desktop.
One-line vs Multi-line conditional statements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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