Backslash '\' in console.log() not appearing

I'm trying to use a back slash in console.log() and within <p></p> but it seems that when the page loads, all back slashes are removed.

Example JS

console.log('\m/ Lets rock. \m/');


m/ Lets rock. m/

How can I prevent it from being removed?

EDIT: Backslash not forward slash. Running this on node.js with express, within the <head> tags of layout.jade. Backslash visible in REPL, but not when running on node in the web browser (Chrome & Firefox).


If m/ Lets rock. m/ is your result, I see forward slashes.

If you mean backslashes, escape them to show that the string wants a literal backslash:

console.log('\\m/ Lets rock. \\m/');

Otherwise, JavaScript interprets this as a \m EscapeSequence. That's why you need the \\ EscapeSequence.

The solution was that the backslashes needed to be double escaped:

console.log('\\\\m/ Lets rock. \\\\m/');

...apparently the backslashes are processed as escaped characters twice (once in the initial string creation, then again for some other purpose).

So the string creation gives us:

'\\m/ Lets rock. \\m/'

...then the subsequent processing results in:

'\m/ Lets rock. \m/'

Need Your Help

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.