Applescript text delimiter replace line to /n
Since you didn't actually say what's going wrong when you try to insert \n into your string, I had a little think and then I remembered that there's a setting in Script Editor:

So, if I'm guessing along the right lines here, I'm suspecting you currently have this option unchecked, which means that whenever you try to type an escaped line-break like &quot;\n&quot;, Script Editor automatically replaces it with a physical line-break whilst you're editing, which then leads to your syntax error issues with JavaScript.
[ Don't forget to escape the newline character twice before sending it to your JavaScript code if doing so within AppleScript: \\n.  If you are entering it directly into the developer console inside the web browser, the single escape \n is fine. ]
So, Option 1, is to adjust this formatting setting in Script Editor.  Option 2 is to stop using Script Editor and use something like Script Debugger or Atom.