JavaScript JavaScript Basics Introducing JavaScript The Console Challenge Answer

Jane Volin
Jane Volin
4,193 Points

What 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
Nick Yoho
6,957 Points

It 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
MOD
Jason Anders
Treehouse Moderator 143,871 Points

Like 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.

:) :dizzy: