4 ms·
There is no difference in JavaScript, they have the same semantics & meaning. However, single quotes have two advantages (IMO, since this is obviously subjecti
by grncdr 10y ago
There is no difference in JavaScript, they have the same semantics & meaning.
However, single quotes have two advantages (IMO, since this is obviously subjective):
1. can be typed without shift on US keyboard layout
2. I use double quotes inside string literals (e.g. for quoting bad input in error messages) more often than single quotes (mostly used for contractions) so not having to escape double quotes by default is convenient.
Standard (and I guess eslint?) support "single quotes unless a single quote appears in the string", which is ideal (for me).
- paulddraper 10y agoAlso, double quotes are in HTML attributes, and JS can be embedded in HTML attributes and vice versa (though it's less common nowadays)
- TheAceOfHearts 10y agoHTML supports both single-quotes and double-quotes.
- paulddraper 10y agoTrue, and XML as well. But double-quotes are by far the norm. (Why? I don't know... :)