views:

35

answers:

2

We can work with escape sequence in strings on JavaScript. 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?

+2  A: 

No, there's not. However, there are RegExp literals:

/foo\s+bar/
Matthew Flaschen
+1  A: 

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).

Aillyn
This requires E4X, which only works in Firefox.
bobince
Aw, I was getting my hopes up for sensible multi-line strings. XML literals seemed fishy though.
adamse