Stefan said:
Fair enough, "unescaped double quote", then.
The example was meant to include all contained white space. Its result
would be "(...) multi-line\n string (...)", because it was indented.
ACK. Sorry, trimming the leading spaces when quoting is a bug of my
newsreader that I should have been aware of.
Some examples are Perl, PHP, Ruby, and Bash scripts. There are others.
Perl and Ruby I do not know well enough. Bash (in fact, all Bourne-shell
compatible shells, if I am not mistaken) I know well, but I forgot about
them.
Still it remains to be seen if there are enough programming languages that
do not require special syntax to justify your "many". For example, it does
not apply to the following languages I know rather well: BASIC (and
variants), Pascal (variants, and derivates), C (variants, and derivates),
Tcl (and derivates), Java, and Python. (And maybe I forgot some.)
The two usual workarounds are
var str = "I wish\n"
+ "I was\n"
+ "a multi-line string";
Joining an Array of strings on newlines appears to be easier to
maintain:
var str = [
"I wish",
"I was",
"a multi-line string"
].join("\n");
I guess that's a matter of preference. I think the concatenation is more
readable.
If you align `=' and `+', but you waste characters then and have to take
care not to forget a trailing "\n".
It is not generally faster.
and concatenation of literals can be optimized away by the parser.
True.
It's also different text, so of course they aren't equivalent. The
spaces are unimportant, I was talking about the line breaks.
But spaces are important in that to have equivalent value (regardless of
the words) you need to write
var str = "I am the closest thing\
to multi-line strings that we can get\
with JavaScript";
which is harder readable.
I've never seen a browser where it didn't work,
It does not appear to work in Opera before version 10.10, so if what you
say is true, you must have never tested with Opera (10.10 is currently the
latest version).
In which browsers (other than supporting the implementations above) do you
remember this to have worked, i.e. that
var s = "foo\
bar";
would be equivalent to
var s = "foobar";
?
PointedEars