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

Part of the video is learning how to show quotes in a string ""

I know template literals aren't shown at this point but to encourage people that later on there is a quicker way, you could also research template literals.

My code:-

const message = "I'm a programmer!" ; surround "I'm a programmer!" with backticks ``
console.log(message);

The above shows "I'm a programmer!" in the console.

2 Answers

Steven Parker
Steven Parker
231,269 Points

You can also get the same result just as quickly by surrounding it with apostrophes '' ("single quotes").

Best practice would be to only use backticks to create a template literal when you will also be using one or more substitution tokens (something like ${name}) in the literal.

Never used single quotes, Guil says to choose either single or double and stick with it, so I stuck with double. However your right you do interpolate into the template literals. 👍

Steven Parker
Steven Parker
231,269 Points

I also generally use double quotes. But in this case the string contains double quotes, so this would be a good place to use single ones to enclose the string.

You can still enclose the whole thing in double quotes, but you'd need to escape each of the quotes that is part of the content by preceding it with a backslash ("\").

Tony Idehen
Tony Idehen
8,060 Points

Better to use either single or double quotes but put a backslash after I ie " I\'m a programmer!"; or ' I\'m a programmer!';

Steven Parker
Steven Parker
231,269 Points

The backslash escapes the character behind it (in this case the apostrophe). But you don't need them in this example since the surrounding quotes use a different character.