4 ms·
singlequotes for strings is very much a standard thing in JS. And two space indentation is fairly common as well. The no semicolons and space after function nam
by jsmith0295 10y ago
singlequotes for strings is very much a standard thing in JS. And two space indentation is fairly common as well. The no semicolons and space after function name are really the weird things here.
- sratner 10y agoI thought so too at first, as those were the only things that disagreed with my previous style. However, I've been using "standard" for a bit now, and have to say that both of those decisions have really grown on me in light of ecma2015 features. Space after function name works well with generator functions and yield. Semicolon placement has become somewhat less consistent with the new object literal and class syntax and skipping them everywhere has saved me from constantly trying to remember whether I need one after a particular function or method definition.
- Grue3 10y agoWhy would you prefer single quotes over double quotes? An apostrophe is not just punctuation in English, it is necessary to preserve the meaning of certain words (like "its"/"it's"). So in a way, it can be considered to be another, albeit rare, letter of the alphabet. Now if somebody proposed to delineate strings with the character "x" everyone would agree it's a bad idea. For the same reason, using "'" to delineate strings is also bad, and shouldn't be encouraged.
- robin_reala 10y agoBecause a lot of JS developers have traditionally manipulated strings of HTML, which have standardised on double quotes for attributes. Also, straight quotes as punctuation are ugly; ‘ and ’ look much nicer.
- WorldMaker 10y agoThere's also the subtle laziness that double quotes require an extra keypress (Shift). It's not a great reason to prefer single quotes over double quotes, but it is a useful reason if you are writing a lot of strings. JS has a lot of things that key off strings (because it doesn't have a proper enum type and the Symbol type is too new for a lot of usage yet), so you type a lot of "non-English text" strings, so single quotes make a lot of sense for the majority of uses of strings in JS. English text I typically still "double quote" or `template string quote`.
- tlrobinson 10y agoUntil you mentioned it I was not even conscious of the fact that double quotes required pressing shift, yet I type hundreds of them every day.