Double quotes vs single quotes in JavaScript [duplicate] Double quotes vs single quotes in JavaScript [duplicate] javascript javascript

Double quotes vs single quotes in JavaScript [duplicate]


The difference is that you don't need to escape single quotes in double quotes, or double quotes in single quotes. That is the only difference, if you do not count the fact that you must hold the Shift key to type ".


It doesn't matter unless you're trying to write JSON, in which case you must use double quotes for object literals.


There is no special difference between single and double quotes (like it is in PHP).

The only actual difference is that you can write a double quote " in a single-quoted string without escaping it, and vice versa.

So, if you are going to output some HTML in your JavaScript, like this:

<div id = "my_div"></div>

single quotes are more useful :-)