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 jQuery Basics Working with jQuery Collections The .each() method

sam hankins
sam hankins
9,372 Points

Can someone explain when I should be using single quotes vs. double quotes?

Trying to figure out why single quotes worked here but double quotes didn't. Any guidance on how to remember that rule of when and where to use witch would be helpful! Thanks! :)

2 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,624 Points

Hey Sam,

You weren't very clear with the question, so I'm guessing when I think you're referring to this line: '<input type="checkbox"/>'?

If you are, then only single quotes will work because there is a set of double quotes already inside. If you use double quotes, then the interpreter sees an opening - closing - opening - closing set of quotes.

Whenever you have quotes inside of quotes, they cannot be the same unless you escape them.

In short. it doesn't matter which ones go where as long as they are different. So "<input type='checkbox'/>" would also work.

Hope that was what you were asking. :) :dizzy:

To avoid issues, I always will use double quotes as my default, and then, if I need quotes again within the double quotes, I will use single quotes. This way, I can usually avoid using the escape character.