My personal style guide is to copy Erlang: double quotes for text, single quotes for programmatic strings (atoms/symbols). The single quote is slightly more convenient to type on a qwerty keyboard, but text regularly contains single quotes (apostrophes). It also provides a semantic visual shortcut.
Mainly our rationale is, pick one and be consistent. Single quotes where there first so they win, same deal with indentation amount.
Note that this is easier in Python than JavaScript because Python provides more string delimiters:
'He said hello.'
'He said "hello".'
"Don't say hello.'
'''Don't say "hello".'''
r'Some regex\sstuff' 'He said hello.'
'He said "hello".'
"Don't say hello."
`Don't say "Hello".`
/some regex\sstuff/
Mainstream support just isn't there yet.Proper typography solves all.
My toy programming language uses “ and ” for string literals. It counts nesting, so you can write “Don’t say “Hello””. There is no escaping. In fact, you can quote any piece of code by simply enclosing it in “ and ”. Code is commented out by turning it into an unused string literal.
I can't personally imagine this solution would be any less confusing, given that the new preferred apostrophe character according to this source is specifically a right single quote character.
Not on my keyboard.
Also, C uses double quotes (and JSON, and many, many more languages). That used to be my rationale. These days I get away with saying that 'foo' and `foo` look too similar.
If I have HTML in a JavaScript string, I don't quote the attributes at all unless necessary, instead focusing on more pressing matters like how to get that shit out of my JavaScript.
You can escape them, but that's an extra pain and strain on readability; you can use some other character but that will usually cause problems down the road.
Why so many people insist on single quotes is a mystery...
So it's much nicer to write
'<a href="www.google.com">Google</a>'
than to constantly escape argument strings. `<a href="${ site.url }">${ site.name }</a>` "<a href='www.google.com'>Google</a>"
Will work as well though.https://github.com/airbnb/javascript/tree/master/react#quote...
'{ "foo": "bar" }'
when you could write JSON.stringify({ foo: "bar" })
and get a static guarantee of valid JSON?
I guess it's just a stylistic choice in the end, but when we set up our own internal/informal style guide, my teammate and I spent a little while trying to come up with a justification for single vs double quotes. We ended up choosing double quotes based on the fact that JSON already made that decision for us: it requires strings be double-quoted.
(Although again, it's far from an important matter, as long as you're consistent), anybody has interesting rationales to share in favor of single quotes?