Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
211,156 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.

Jason Robbins
Jason Robbins
7,117 Points

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 \