Question is old but I want to give a clear answer and explain why this happens for others who comes here:
First of all, there is nothing wrong with the JavaScript code line in the question. It is absolutely valid and produces no parsing error. The reason for the problem in Vitalmax' case was most likely because he/she didn't posted additional code, which surrounded that line.
Here is an example in PHP, which shows why the JS parser complains about the syntax:
<?php
echo "alert('Hello again! This is how we\nadd line breaks to an alert box!');";
?>
The parsed server-side output then is (this is what the browser gets):
alert("Hello again! This is how we
add line breaks to an alert box!");
In JavaScript, strings must not have real line breaks.* Instead, they must always be escaped (like: \n), so the browser complains about an "unterminated string literal" at the real line break. There are some exceptions to this rule, like for horizontal tabulators (\t). So (in this case) you have to escape the line breaks twice with \\n. So when PHP parses and converts it from \\n to \n, JavaScript can convert it from \n to [real line break].
Correct PHP example would be:
<?php
echo "alert('Hello again! This is how we\\nadd line breaks to an alert box!');";
?>
Or:
<?php
echo 'alert("Hello again! This is how we\nadd line breaks to an alert box!");';
?>
In the second case you don't have to double escape it because escaped characters within PHP strings with single quotes are not decoded (\n stays \n).
*Note: It is possible to use the special quote sign ` which allows real line breaks in JS. Example:
alert(`Hello again! This is how we
add line breaks to an alert box!`);