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 trialJane Volin
4,193 PointsWhat is the difference between using single or double quotes around a statement?
It seams like they serve the same purpose. I recently completed the code academy java script course and they use single quotes throughout their script. Just curious about what is the best practice and why?
2 Answers
Nick Yoho
6,957 PointsIt depends how you use it, but they do the same thing. A double quote surrounding a string that has a word containing an apostrophe in it will work normally. If you have single quotes around the same string you will get an error unless you add a \ within the word with the apostrophe (that\'s) to escape it.
Jason Anders
Treehouse Moderator 145,860 PointsLike Nick has said, there is no difference. It really is personal preference, just remain consistent in your code.
Just an additional note... with some languages (i.e. PHP), double quotation marks act differently than single quotation marks, and using one instead of the other could break you code. But for the most part (and most languages) it really is just a preference.
:)