you can escape end of line with backslash character \, like so:

 $.each(data.result, function(){
 $("ul").append("<li>Name: " + this['name'] + "</li> \
     <li>Age: " + this['age'] + "</li> \
     <li>Company: "+this['company']+"</li> \
     <br />");
 });

This is due to the fact that Javascript automatically insert semi-columns sometime on line end. And in this case, you string weren't close. Another solution is to close each string on each line, and using + to concat them all.

 $.each(data.result, function(){
 $("ul").append("<li>Name: " + this['name'] + "</li>" +
     "<li>Age: " + this['age'] + "</li>" +
     "<li>Company: "+this['company']+"</li>" +
     "<br />");
 });

(Unrelated, but you <br/> aren't allowed inside a <ul> element)

Answer from Simon Boudrias on Stack Overflow
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ javascript-multiline-string-how-to-create-multi-line-strings-in-js
JavaScript Multiline String โ€“ How to Create Multi Line Strings in JS
August 10, 2022 - There are three ways to create strings that span multiple lines: By using template literals. By using the + operator โ€“ the JavaScript concatenation operator.
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Template_literals
Template literals (Template strings) - JavaScript | MDN
Like normal string literals, you can write a single-line string across multiple lines for source code readability, by escaping the newline with a backslash (\): ... Without template literals, when you want to combine output from expressions with strings, you'd concatenate them using the addition ...
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Learn_web_development โ€บ Core โ€บ Scripting โ€บ Strings
Handling text โ€” strings in JavaScript - Learn web development | MDN
You can declare template literals over multiple lines. Inside a template literal, you can wrap JavaScript variables or expressions inside ${ }, and the result will be included in the string: ... const one = "Hello, "; const two = "how are you?"; const joined = `${one}${two}`; console.log(joined); ...
๐ŸŒ
Codefinity
codefinity.com โ€บ courses โ€บ v2 โ€บ b7a3525b-7a95-427a-848b-da96efeb9cf8 โ€บ f5c3542f-099f-49c4-90c1-66a29c3dfc44 โ€บ 962e94ff-a171-4b7b-a25f-3ea2e0e415e1
Learn Multiline Strings. Concatenating | JavaScript syntax
We can implement a multi-line string by concatenation of every line of the multi-line string to the variable. Below we have a code example for it: 1234 let myStr = "This is my" + " multiline String " + " which is amazing"; console.log(myStr); ...
๐ŸŒ
Flexiple
flexiple.com โ€บ javascript โ€บ javascript-multiline-string
JavaScript Multiline String โ€“ How to Create Multi Line Strings in JS - Flexiple
Creating multiline strings in JavaScript can be achieved using various methods. One approach is to use backticks (\`\`) to enclose the string content, allowing for line breaks without the need for escape characters.
๐ŸŒ
ReqBin
reqbin.com โ€บ code โ€บ javascript โ€บ v5jbgquu โ€บ javascript-multiline-string-example
How do I create a multiline string in JavaScript?
The newline character is denoted by "\n". We can use this character to stretch our string across multiple lines. JavaScript Multiline String using Backslash Example ยท let str = " Javascript \n Multiline \n String \n Example"; console.log(str); ...
๐ŸŒ
Eran Stiller
eranstiller.com โ€บ javascript-multiline-strings
Top 4 Ways to Create JavaScript Multiline Strings
September 17, 2023 - Hereโ€™s a quick example: Instead of concatenating strings and inserting new line characters, you can wrap your text in backticks (`). This allows your JavaScript multiline string to span multiple lines without extra fuss.
Find elsewhere
๐ŸŒ
Go Make Things
gomakethings.com โ€บ three-ways-to-create-multiline-strings-with-vanilla-js
Three ways to create multiline strings with vanilla JS | Go Make Things
<article> <h1>Hi there, Chris!</h1> <p>How are you today?</p> </article> ... Letโ€™s dig in. With string concatenation, you use the concatenation operator (+), and treat each line as its own separate string.
๐ŸŒ
Designcise
designcise.com โ€บ web โ€บ tutorial โ€บ how-to-create-multi-line-strings-in-javascript
How to Create Multi-Line Strings in JavaScript? - Designcise
June 3, 2020 - You can use escaped newlines (\) at the end of each line of string to make a multi-line concatenation, for example:
๐ŸŒ
Tutorial Republic
tutorialrepublic.com โ€บ faq โ€บ how-to-create-multiline-strings-in-javascript.php
How to Create Multiline Strings in JavaScript
You can use string concatenation (through + operator) to create a multi-line string. The following example will show you how to compose some HTML content dynamically in JavaScript using the string concatenation and print it on a webpage.
๐ŸŒ
Techie Delight
techiedelight.com โ€บ create-multi-line-strings-in-javascript
Create multiline strings in JavaScript
Techie Delight is a leading platform for technical interview preparation. Prepare for your coding interview with Techie Delight. Improve your algorithmic skills and crack interviews with top tech companies.
Top answer
1 of 16
4556

ECMAScript 6 (ES6) introduces a new type of literal, namely template literals. They have many features, variable interpolation among others, but most importantly for this question, they can be multiline.

A template literal is delimited by backticks:

var html = `
  <div>
    <span>Some HTML here</span>
  </div>
`;

(Note: I'm not advocating to use HTML in strings)

Browser support is OK, but you can use transpilers to be more compatible.


Original ES5 answer:

JavaScript doesn't have a heredoc syntax. You can escape the literal newline, however, which comes close:

"foo \
bar"
2 of 16
1559

ES6

As the first answer mentions, with ES6/Babel, you can now create multi-line strings simply by using backticks:

const htmlString = `Say hello to 
multi-line
strings!`;

Interpolating variables is a popular new feature that comes with back-tick delimited strings:

const htmlString = `${user.name} liked your post about strings`;

This just transpiles down to concatenation:

user.name + ' liked your post about strings'

ES5

Google's JavaScript style guide recommends to use string concatenation instead of escaping newlines:

Do not do this:

var myString = 'A rather long string of English text, an error message \
                actually that just keeps going and going -- an error \
                message to make the Energizer bunny blush (right through \
                those Schwarzenegger shades)! Where was I? Oh yes, \
                you\'ve got an error and all the extraneous whitespace is \
                just gravy.  Have a nice day.';

The whitespace at the beginning of each line can't be safely stripped at compile time; whitespace after the slash will result in tricky errors; and while most script engines support this, it is not part of ECMAScript.

Use string concatenation instead:

var myString = 'A rather long string of English text, an error message ' +
               'actually that just keeps going and going -- an error ' +
               'message to make the Energizer bunny blush (right through ' +
               'those Schwarzenegger shades)! Where was I? Oh yes, ' +
               'you\'ve got an error and all the extraneous whitespace is ' +
               'just gravy.  Have a nice day.';
๐ŸŒ
Career Karma
careerkarma.com โ€บ blog โ€บ javascript โ€บ javascript: multiline strings using \n and template literals
JavaScript: Multi Line Strings | Career Karma
December 18, 2020 - You now have the ability to write JavaScript multi line strings in both ES6 and ES5 syntax! There are three ways to create a multiline string in JavaScript. We can use the concatenation operator, a new line character (\n), and template literals.
๐ŸŒ
David Walsh
davidwalsh.name โ€บ multiline-javascript-strings
Multi-Line JavaScript Strings
November 2, 2012 - The JavaScript language performs automatic semicolon insertion at the end lines, so creating multiline strings usually ends up looking something like this: var multiStr = "This is the first line" + "This is the second line" + "This is more..."; ...
๐ŸŒ
Willmaster
willmaster.com โ€บ library โ€บ tutorials โ€บ multi-line-strings-in-javascript.php
Multi-Line Strings in JavaScript
Another way to deal with multi-line strings in JavaScript is to append each following line to the previous one, making one virtual long line by concatenating the three lines.
๐ŸŒ
Delft Stack
delftstack.com โ€บ home โ€บ howto โ€บ javascript โ€บ javscript multiline
How to Write a Multiline String in JavaScript | Delft Stack
March 11, 2025 - One of the most straightforward and modern ways to create multiline strings in JavaScript is by using template literals. Introduced in ES6, template literals allow you to embed expressions and create strings that span multiple lines ...
๐ŸŒ
Keyboard Maestro
forum.keyboardmaestro.com โ€บ questions & suggestions
How to Create JavaScript Multiline String Literals (Template Literals) - Questions & Suggestions - Keyboard Maestro Discourse
December 13, 2016 - That's the hard way to do multi-line strings. Quote to start, quote to end, multiple lines each ending with a backslash will do it. Even better, use template literals.
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ 4 ways to concatenate strings in javascript
4 Ways to Concatenate Strings in JavaScript - Scaler Topics
January 6, 2024 - Using these template literals, we can also use multi-line strings. Here, with the help of $ and curly braces, we can embed a variable in our string quoted under back-ticks, indicating string concatenation :) ... In this JavaScript example, we have initialized three string variables at the start, and then with the concept of template literals, we have embedded str1, str2, and str3 in the string - final_str quoted under back-ticks.
๐ŸŒ
Sling Academy
slingacademy.com โ€บ article โ€บ stitching-multiple-lines-together-for-display-using-javascript-string-concatenation
Stitching Multiple Lines Together for Display Using JavaScript String Concatenation - Sling Academy
let line1 = "These lines "; let line2 = "are concatenated "; let line3 = "using the plus "; let line4 = "operator."; let fullText = line1 + line2 + line3 + line4; console.log(fullText); // Output: These lines are concatenated using the plus operator. The concat method is another way to concatenate strings in JavaScript. It's less commonly used but can be beneficial when chaining multiple concatenations: