Javascript CR + LF will break the line?

When saving '\ n \ r' inside a string constant, the Javascript engine throws an error, for example, "unterminated string", etc.

How to solve this?

Additional info: I mainly want to use Javascript to select text in the HTML TEXTAREA field and insert new lines. When I try to populate these constants, I get an error.

+3
source share
2 answers

String literals should not contain simple line breaks, such as CR and LF:

A < LineTerminator , \. - escape-, ​​ \n \u000A.

:

"foo
bar"

escape-, :

"foo\nbar"
+9

(\) .

:

    window.alert('foo\
    bar');
0

Source: https://habr.com/ru/post/1785957/


All Articles