SyntaxFix
Write A Post
Hire A Developer
Questions
You have to escape the backslash, so try this:
str = "Hello\\nWorld";
Here are more escaped characters in Javascript.