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 trialAndré Sousa
Full Stack JavaScript Techdegree Student 735 PointsUncaught 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
231,269 PointsA 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
Full Stack JavaScript Techdegree Student 735 PointsThank 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.
Steven Parker
231,269 PointsI expanded my answer.
André Sousa
Full Stack JavaScript Techdegree Student 735 PointsThank you very much Steven, that was it!
Jason Robbins
7,117 PointsAnother possible solution:
const multiline = "Here is a string \n with two lines"; console.log(multiline);
Muhammad Khan
Courses Plus Student 8,772 PointsHi 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 \