Cancel escape-sequence on JavaScript
We can work with escape sequence in strings on JavaScript开发者_StackOverflow中文版. For example, I can write \\
and it means \
. But I don't want to use a escape sequence.
I know that on C# I can write @"My string" and I don't need to escape anything. Is there similar syntax in JavaScript?
No, there's not. However, there are RegExp literals:
/foo\s+bar/
There is no such syntax, but there is a work around:
var string = (<r><![CDATA[
Now you can put a whole lot of stuff here.
Including new lines, and all sorts of symbols: \ " '
]]></r>).toString();
Because it's so verbose it's only worth using this when you have something that would be otherwise unreadable (eg: a pretty long string with a bunch of characters that need escaping).
精彩评论