Skip to content

Instantly share code, notes, and snippets.

@chrisjpowers
Created September 18, 2012 15:10
Show Gist options
  • Save chrisjpowers/3743662 to your computer and use it in GitHub Desktop.
Save chrisjpowers/3743662 to your computer and use it in GitHub Desktop.
JavaScript Syntax Question
// Do you prefer...
if (a) {
doA();
} else if (b) {
doB();
} else {
doC();
}
// or...
if (a) {
doA();
}
else if (b) {
doB();
}
else {
doC();
}
// Similarly, this...
try {
doSomething();
} catch (e) {
console.log(e);
}
// or...
try {
doSomething();
}
catch (e) {
console.log(e);
}
@iaman
Copy link

iaman commented Sep 19, 2012

I've got to say that I prefer the less condensed syntax; How much code I can fit on my screen is not a metric I particularly care about, but how quickly I can parse code very much so is something I care about. Placing the conditionals immediately after the braces can lead to some extremely samey line lengths and that is one of the fastest ways to get me to miss something at a glance.

@bf4
Copy link

bf4 commented Sep 19, 2012

the fist captures the idea of a logical block better, which, I think, is more valuable than any potential lost clarity by condensing it. (also, as mentioned, saves screen real estate)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment