Possible Duplicate:
When to Use Double or Single Quotes in JavaScript
Are there differences between ' and "
I am wondering if there is a difference between using single quotes vs double quotes in JavaScript (JQuery selectors etc.).
Both seem to work just fine, so is there a difference?
Both single (' ') and double (" ") quotes are used to represent a string in Javascript. Choosing a quoting style is up to you and there is no special semantics for one style over the other. Nevertheless, it is important to note that there is no type for a single character in javascript, everything is always a string!
They are the same thingIn JavaScript, a string is a sequence of characters enclosed in single or double quotes. The choice of quoting style is up to the programmer, and either style has no special semantics over the other. There is no type for a single character in JavaScript - everything is always a string.
General Usage Rules In America, Canada, Australia and New Zealand, the general rule is that double quotes are used to denote direct speech. Single quotes are used to enclose a quote within a quote, a quote within a headline, or a title within a quote.
Double quotes eliminate the need to escape apostrophes (as in contractions).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With