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

Single quote and double quote on strings

Why some strings are wrapped in single quote and others in double quote in this video? Mercury is in single quote and the questions are in double quote. I thought quotation for strings should be consistent throughout your program.

1 Answer

Trent Ungard
Trent Ungard
10,533 Points

Hello!

There's no reference in your question to the specific video you're watching, but there could be a few reasons for something like this.

First, is it a template literal that you're referencing? If so, there are various reasons to use them but I personally don't use them unless I need to interpolate a variable into my string. In some places, my code may say

const value = "JavaScript" and in others, const someVar = ${value} is cool

Otherwise, using single and double quotes in different places is only something I would do if I needed to embed quotation marks within a string, such as '"hello there", I said'. In that case, the specific strings wrapped in single quotation marks are only being used because I want to use double quotes within.

It could also be the case that there was a typo, as it is best practice to use the same quotation methodology throughout your code.

Hope this helps!