2 ms·
My assumption is that for JS single quotes are used because double quotes are the standard for HTML, and this allows for easier use of JS code in HTML attribute
by kbenson 11y ago
My assumption is that for JS single quotes are used because double quotes are the standard for HTML, and this allows for easier use of JS code in HTML attributes for JS events (e.g. onclick="alert('foo');").
I assume JS allows both because of the languages that came before, such as Perl, where it was a convenience to make it easier to include either double quotes or single quotes (contractions) within a string without escaping (but Perl goes much farther than that with the q and qq operators).
In other languages, such as C/C++ single quotes aren't used for string, but for character literals.