Difference between single quotes and double quotes in Javascript

Michael Lumbroso picture Michael Lumbroso · Jun 30, 2010 · Viewed 80.9k times · Source

I know that in PHP, the only difference between double quotes and single quotes is the interpretation of variable inside a string and the treatment of escape characters.

In JavaScript, I often see double quotes used in strings. Is there a particular reason for that, or are single quotes exactly the same as double quotes?

Answer

karim79 picture karim79 · Jun 30, 2010

You'll want to use single quotes where you want double quotes to appear inside the string (e.g. for html attributes) without having to escape them, or vice versa. Other than that, there is no difference.

However, note that JSON (JavaScript Object Notation) only supports double quoted strings.