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

24

u/e_man604 Apr 01 '18

Why is single quote (') preferred over double quote (") ? For me it makes sense to use double to remain same when dealing with c++ for instance.

67

u/[deleted] Apr 01 '18

"Being same as C++" should be quite low in priority for a JavaScript style guide.

One reason why single quotes is no shift. It's faster to type, and who cares what it is, anyway, as long as it's consistent.

3

u/tencircles Apr 01 '18

It's faster to type

Not really, though I hear this argument all the time. Your pinky rests on the shift key. A isn't slower to type than a (or shouldn't be). The reason to prefer double quotes is to keep consistency with JSON, HTML, and other languages. Personally I prefer backtick to both because it's simply cleaner in a lot of cases. Historically the argument for single quotes was so that you didn't have to escape double quotes in your html strings when writing jQuery apps, but that doesn't really apply in modern JS dev.

18

u/[deleted] Apr 01 '18

Your pinky rests on the shift key.

No, that's not where my pinky rests.

https://en.wikipedia.org/wiki/Touch_typing#/media/File:QWERTY-home-keys-position.svg

1

u/web__dev Apr 02 '18

That's what I was thinking. They call it "home row" for a reason.

1

u/tencircles Apr 02 '18

which was developed and designed for the english language, not javascript/programming which has a completely different set of concerns/common keys.