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

CSS

Some strings are wrapped in quotes: "string" others are wrapped in single marks: 'string' How do I know which to use?

For example, when assigning strings to a variable, i write const myString = 'waffle bagel'; but when referring to a string in a function, I write: console.log("waffle bagel");

Is there a rule to memorize when to use "" and when to use ''

1 Answer

Hi Cody!

Some useful articles:

https://javascript.plainenglish.io/the-real-difference-between-single-quotes-and-double-quotes-in-javascript-3d00bf720bcd

https://bytearcher.com/articles/single-or-double-quotes-strings-javascript/

There is a big difference in PHP:

https://dev.to/morinoko/double-quotes-vs-single-quotes-in-php-2e5n

One place this gets tricky is when you have to store HTML in a value:

const myHTML = '<div class="myDiv">My Div</div>';

Or if you have to store HTML in a JSON file (I had to use &quot for the double quote):

const JSON = [
  {
     "html": "<div class=&quotmyDiv&quot>My Div</div>"
]

I hope that helps.

Stay safe and happy coding!