0

Is there any difference between using '' or "" in JavaScript (example below)?

var sports = ['soccer', 'baseball', 'basketball']

or

var sports = ["soccer", "baseball", "basketball"]

This array is a super simple example, but would there any difference or cases in more advanced JavaScript where '' would make more sense than "" or vice-versa? Learning through Codecademy and they've used both interchangeably without any explanation.

  • Nothing. They are the same. `'soccer' === "soccer"` – rgthree Feb 12 '15 at 04:48
  • 1
    [When to Use Double or Single Quotes in JavaScript](http://stackoverflow.com/questions/242813/when-to-use-double-or-single-quotes-in-javascript) and [Difference between single quotes and double quotes in Javascript](http://stackoverflow.com/questions/3149192/difference-between-single-quotes-and-double-quotes-in-javascript) – Jonathan Lonowski Feb 12 '15 at 04:49
  • JavaScript doesn't define a significant difference between them, so in most cases they're interchangeable. The only difference is you must escape the quotation you chose for the string literal when it's also included as a character -- e.g., `'Foo\'s' === "Foo's"`. – Jonathan Lonowski Feb 12 '15 at 04:52
  • @JonathanLonowski- Ah, exactly what I was looking for, but I wasn't searching for it correctly. I'm new to Stack Overflow...should I just delete this entire post since it's already been asked? – timbucktieu Feb 12 '15 at 04:54

0 Answers0