Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Double quotes vs single quotes in JavaScript [duplicate]

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?

like image 495
TGH Avatar asked Mar 31 '12 21:03

TGH


People also ask

Should I use double quotes or single quotes in JavaScript?

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!

Are single and double quotes the same JavaScript?

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.

What is the difference between single quotes and double quotes?

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.

What is the advantage of using double quotes?

Double quotes eliminate the need to escape apostrophes (as in contractions).


2 Answers

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

like image 83
CR Drost Avatar answered Oct 04 '22 10:10

CR Drost


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

like image 43
BluesRockAddict Avatar answered Oct 04 '22 10:10

BluesRockAddict