Skip to content
Advertisement

Is there a way to display multi-line string in Javascript?

I have a function which receives a single line string and displays it without a problem using an alert pop up from alertify JS but when its a multi-line string it gives an error saying Uncaught SyntaxError: Invalid or unexpected token . Below is my function:

JavaScript

The changes is the string am receiving and am displaying it in an alert box. Below is where am getting the changes from. I am getting this string from an object and passing it to my function

JavaScript

When i click this button it does not send the multi-line string to my function but when its a single line string it works without a problem

The sample text which brings the error is like below:

added footer

added heder

added content

Below is a fiddle which i have replicated the error Js Fiddle

Advertisement

Answer

if the problem was multi lines strings, you can use the back ticks ` to print the multi line strings in javascript

JavaScript

and in your case would be:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement