Javascript – Should I use double-quotes or single-quotes for quoting strings if I want to be consistent across multiple languages


In JavaScript, it doesn't seem to matter whether you use single quotes or double quotes when writing strings. However, some programming languages treat them differently.

Is one more reliable than the other across multiple programming languages? Are there any pros or cons using one rather than the other (apart from when apostrophes or quotes are in the string)?

I would like to choose one and then be able to use it across multiple programming languages—with it meaning the same thing (if that's possible).

Best Solution

In a lot of scripting and shell languages, there is a significant difference between double and single quotes. For example, in Perl and a lot of Unix shells, when you use double quotes, the interpreter will parse through your string and try to do any substitutions for any variables in the string. If you use single quotes, the interpreter will not try to do anything fancy with the string; it will treat it as a plain literal.

In other languages like C++ or Java, double quotes are used for strings, and single for single character literals.

Every language might treat quotes differently. I think in Javascript it might not matter which one you use, but it would be best to do some research on the best practices, then just pick one methodology and be consistent. I've seen some examples where the person chose to use double quotes in HTML and single in Javascript, but I'm not sure if that's the "standard."