1

Possible Duplicate:
Difference between single quotes and double quotes in Javascript

I read some codes, it looks like a lot of people like to use single quote for string. I am coming from c#/Java world, usually we use double quote for string.

Any benefit for using single quote, I know single/double are equivalent in JS. But is there any pro and con to use single/double quote?

Community
  • 1
  • 1
Adam Lee
  • 24,710
  • 51
  • 156
  • 236
  • Absolutely no difference semantically between single- and double-quote characters for string delimiting. – Pointy Aug 17 '12 at 23:41

5 Answers5

1

It's a matter of preference. There is no difference in JavaScript.

Personally, I prefer to use single quotes. It makes it easier for using double quotes in HTML that you don't have to escape. That may or may not matter to you. What does matter is that you are consistent.

Brad
  • 159,648
  • 54
  • 349
  • 530
1

If you want to write a string containing single quotes it can be convenient to delimit the string with double-quotes and vice versa.

var a = 'abc "def" ghi';
var b = "foo 'bar' baz";

Other than that, it doesn't matter which you use. Be consistent where possible.

Mark Byers
  • 811,555
  • 193
  • 1,581
  • 1,452
0

For the most part, I think the reason is "you don't have to press Shift to get single quotes".

Sometimes choosing the right quotes makes escaping easier, but it's pretty much always personal preference.

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
0

The best reason to use one over the other is the intention to use the other as literal content. This removes the need to escape the character being used as the delimiter.

For example, ' this """ has double quotes' and " this has single '''' quotes"

Wes
  • 42
  • 5
0

There is absolutely no difference. Just don't mix and match.

Jared Drake
  • 982
  • 4
  • 12