This issue is to discuss changing the formatting of strings to default to double instead of single quotes.
This feels like enough reasons to justify the change.
Accidentally pushed to master instead of another branch. Really need to setup branch protection (I've been saying this for ages...). Historically whenever I've tried to revert commits on master and redo them in a separate branch I've always messed up my local checkout so I'm just going to leave it as-is. 8463545ec585b49c650fcad3900e138b3e1dc9dd
I think it would be best to leave them as single quotes. While the frequency of apostrophes is a great point, moving to double quotes adds an extra bit of friction for _every_ (non-interpolated) string in your code.
const s = 'Also, double quotes aren\'t the only way to deal with apostrophes in strings.'
double quotes adds an extra bit of friction for every (non-interpolated) string in your code.
What do you mean?
Instead of just tapping the ' key, it becomes Shift + '. Considering accessibility as a motivating factor for moving from spaces to tabs, it seems like the additional key press might raise some similar concerns. No solid evidence to back to that up though.
That's a good point but you're already pressing shift for other operators. The accessibility rationale for tabs is about how the code is read and processed whereas this is just a cosmetic change.
Depends on your keyboard layout.
You can always use single quotes and let Rome change them to double quotes, I do that with Prettier all the time.
Apostrophes in strings are typographically incorrect; they need to be curly quotes, single or double. Using single quotes for JS strings can help catch this typographical error :-)
There are keyboard layouts (Russian for me, sure there are others) that don't have single quotes at all (the language doesn't use apostrophes), so I've been confused by single quotes for a long time.
Double vs single quotes feels like mostly a matter of personal preference, or how you were "raised". I find double quotes to be more visually pleasing since they're what I've primarily used in every language since I first started coding. Consistency between languages, given JSON requires double quotes, feels like a strong argument for using them whenever convenient.
Doesn’t Rome have RJSON tho, which doesn’t have that constraint?
@ljharb RJSON only allows for syntax ommission and comments. It doesn't add any new data types. Property keys can be unquoted if they're a valid identifier, like in regular JS, but it still requires double quotes.
@ljharb
Apostrophes in strings are typographically incorrect; they need to be curly quotes, single or double. Using single quotes for JS strings can help catch this typographical error :-)
I'm just confused. Are you just noting the difference between apostrophes and single quote characters?
@dcleao i'm saying ' is always incorrect in prose, you want it’s, never it's.
@ljharb But, apart from the possible humor, do you really find that that's a strong argument for using single quotes? I usually use the reverse argument, that using double quotes is best, in one way, because it allows you to use the, so common, single quote, un-escaped. After all, most people use the "non-typographically correct" non-curly single-quote to denote the apostrophe of the possessive case.
By the way, typographically, curly or not, doubles are used preferably to singles ;-), no?
Relevant to note here that we do have a list of unicode characters that look like ASCII that we use to provide syntax error hints:

The file will even product an AST correctly with the recoverable parser (although will fatal unless we add an option to ignore parser syntax errors).
Also relevant, Prettier has an ongoing discussion for making the singeQuote option true by default - https://github.com/prettier/prettier/issues/4102 (I am a fan of double quotes)
Edit: the docs here list my reasoning on the Prettier discussion
Double string quotes. Consistent quote style across all supported languages.
Also relevant, Prettier has an ongoing discussion for making the
singeQuoteoptiontrueby default - prettier/prettier#4102 (I am a fan of double quotes)
This comment in that prettier thread is the main reason why I prefer single quotes in JS. It feels unnatural to write html with two different styles depending on if it is in a .js file or .html file.
In this comment they show evidence that it is the dominating standard in popular npm packages (seems like a good indicator 🤷♂️). Why go against the flow?
- It's much more common for an apostrophe to appear in a string than a quotation mark.
I don't really buy this argument. It might be true that it is more common in a string containing a sentence to have more apostrophes but in the code I write I write way way more strings containing html/selectors with quotation marks.
- JSON only allows double quotes.
That is true but is that really a problem? I have never seen or written syntax correct JSON in JS.
I think it's more likely that we would just skip this argument entirely and use template literals for all strings.
Most helpful comment
I think it's more likely that we would just skip this argument entirely and use template literals for all strings.