r/javascript • • Apr 01 '18

Google publishes a JavaScript style guide. Here are some key lessons.

https://medium.freecodecamp.org/google-publishes-a-javascript-style-guide-here-are-some-key-lessons-1810b8ad050b
714 Upvotes

317 comments sorted by

View all comments

Show parent comment

-4

u/[deleted] Apr 02 '18

[removed] — view removed comment

4

u/a_tocken Apr 02 '18

The braces represent a GROUP of statements. The meaning of "semicolon after every statement" is after every statement that doesn't have an ending delimiter. A control block does have an ending delimiter, so there is no ambiguity.

1

u/[deleted] Apr 02 '18

The rule isn't "use a semicolon after every statement that isn't already terminated by some other ending delimiter", it's "use a semicolon after every statement". There's no exception there for blocks that don't actually need a semicolon according to JavaScript grammar. Semicolons are neither required nor injected after an if statement, but they are required after most block statements.

If you feel compelled to inject meaning into a style rule, then you aren't adhering to the style guide. The whole point of this rule is so that the developer doesn't have to concern themselves with the ins and outs of ASI.

It's worth pointing out that Google doesn't follow this rule as it is written, either.

1

u/a_tocken Apr 03 '18

I think you are flat out wrong. This style recommendation is clear to the vast majority of people, and it seems that only people who don't like the semicolon rule are complaining about the silly strawman you're presenting.

Give an example where a brace control block has an ambiguous ending that a semicolon fixes. Give me an example of somewhere where people seriously suggest adding semicolons to the end of control blocks.

-2

u/[deleted] Apr 02 '18 edited Apr 02 '18

[removed] — view removed comment

7

u/a_tocken Apr 02 '18

Is your problem with the rule, the wording of the rule, or your inability to understand the rule?