if (foo) {
bar;
}
can be shortened to
if(foo) bar;
since it's only one statement in the block.
I'm wondering if the same applies to try/catch... I don't like extra cruft in my code.
if (foo) {
bar;
}
can be shortened to
if(foo) bar;
since it's only one statement in the block.
I'm wondering if the same applies to try/catch... I don't like extra cruft in my code.
Share Improve this question edited Jan 24, 2016 at 5:51 rink.attendant.6 46.2k64 gold badges110 silver badges157 bronze badges asked Nov 14, 2012 at 23:55 wwaawawwwaawaw 7,13710 gold badges35 silver badges42 bronze badges 01 Answer
Reset to default 21According to ECMAScript 5, a block is required, which means you need the curly braces.
https://es5.github.io/#x12.14
TryStatement :
try Block Catch
try Block Finally
try Block Catch Finally
Catch :
catch ( Identifier ) Block
Finally :
finally Block
https://es5.github.io/#x12.1
Block :
{ StatementList opt }
StatementList :
Statement
StatementList Statement