Since it seems like there is no hard and fast answer, what's consistent across languages?
Bash/Powershell/Ruby: " enables interpolation and escape sequences. ' means the string is exactly as it is typed.
C-style languages (Java, C#, C++ etc): " is a string while ' for single characters.
Python/Javascript: no difference. If a string needs to contain ", you might delimit it with ' and vice versa.
JSON: double quotes only. This is the tilting argument.
Across languages, single quotes imply a lack of escape sequences and interpolation.
Typescript has backwards compatibility for ` (back-tick) strings so my preference is to use " (double quote) for non-escaped strings, generally free of white-space and in the following character set:
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-
or [\w\d-]*
in many regex dialects. This means you can copy pasta object literals into JSON and vice versa. Quite useful in practice for little investigations, tests, etc.
For everything else, ` (back-ticks) since it cuts down on escape sequences and enables interpolation.
Note: I am not an advocate of JSON, it just seems inescapable these days ;)
"quotemark": [true, "double"]
– Tintoretto'
which can often be contained within common text output (usually much more than"
), it's good to use doble quotes""
. It's also more consistent with other C-like languages where'
is used for single chars. That being said, it doesn't really matter - rule of thumb - use what's already in the project and be consitent about it. One of the ideologies is also to use""
for textual output and'
for "programming" strings like constant values – Pilch