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 comments

1

u/e_man604 Apr 01 '18

Yes but ' in c++ is char and not string, so its two different things. Sorry if it was a bit weird but I only wondered why single quote was popular by Js community.

I guess it's not to press shift, as others said.

10

u/deliciousleopard Apr 01 '18

using single for code and double for html is the norm, which allows putting html in js strings and js in html attributes without making stuff weird.

0

u/tencircles Apr 02 '18

this is no longer relevant as we have backticks now.

1

u/shaggy756 Apr 01 '18

Yeah anybody arguing that it's faster is full of it.

1

u/ssjskipp Apr 02 '18

It's because " is used as html attributes. When you're using js for what it was designed for, before we had fleshed out browser API, you'd be making a lot of HTML with string contacts.

Go ahead and play the string escape game with large swaths of nested HTML xD

2

u/stratoscope Apr 02 '18

It's because " is used as html attributes.

This is a common misconception. HTML does not require the use of double quotes for attributes. Single quotes are equally valid.

Of course you may choose to use single quotes in JavaScript and double quotes for HTML attributes, but it's just as valid to do it the other way around.

1

u/ssjskipp Apr 02 '18

That's definitely fair, in that HTML is the absolute most permissive markup around.