Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Basics Working with Strings Introducing Strings

André Sousa
seal-mask
.a{fill-rule:evenodd;}techdegree
André Sousa
Full Stack JavaScript Techdegree Student 735 Points

Uncaught SyntaxError

This is my code:

const multiline = "Hello, world. \ This is me. \ Your master.";

(keep in mind this in separate lines)

It is giving me an error, it doesn't let me put a string in different lines.

5 Answers

Steven Parker
Steven Parker
229,657 Points

A multi-line string can be created as a template literal. Use accents ("backticks") instead of quotes or apostrophes to enclose the string body:

const multiline = `Here is a string
with two lines`;

A normal string can be extended to multiple source lines by putting a backslash at the end of the continued line:

const singleline = "Here is a string \
shown on just one line";

Make sure there are no characters (including spaces) after the backslash!

If you still have trouble, make a snapshot of your workspace and post the link to it here so the issue can be replicated.

André Sousa
seal-mask
.a{fill-rule:evenodd;}techdegree
André Sousa
Full Stack JavaScript Techdegree Student 735 Points

Thank you, I hadn't arrive to that part yet. But I am doing exactly as in the video and still get the error, and that is not supposed to happen.

Another possible solution:

const multiline = "Here is a string \n with two lines"; console.log(multiline);

Hi there, I had the same Uncaught SyntaxError in multiline statement. But when I have removed blank space after \ my program is running fine and giving desired output. So, it's important to make sure there is no space or any character after \