-2

Possible Duplicate:
When to Use Double or Single Quotes in JavaScript

I am study JavaScript. I don't understand With JavaScript When we use " " and when we use ' ' ?Please explain for me.

Community
  • 1
  • 1
user737618
  • 181
  • 2
  • 2
  • 7
  • googling for `single or double quote in javascript` returned http://stackoverflow.com/questions/242813/when-to-use-double-or-single-quotes-in-javascript – ninjagecko Jul 13 '11 at 05:45

5 Answers5

4

It doesn't really matter. For the most part is about whether you are using one type of quote inside another.

As an example (all of these are true):

"foo" == 'foo'
"hi \"there\"" == 'hi "there"'
"what's up?" == 'what\'s up?'
"\"eat\" at Joe's" == '"eat" at Joe\'s'
cwallenpoole
  • 79,954
  • 26
  • 128
  • 166
1

For the most part, it doesn't matter which you use. Both indicate a text constant.

As far as explaining the entire language, I think you'll need a book for that.

Jonathan Wood
  • 65,341
  • 71
  • 269
  • 466
1

They basically are arbitrary, but you can nest one inside the other without issues for example: "hello 'world'"

normally you would have to do "hello \"world\""

switz
  • 24,384
  • 25
  • 76
  • 101
0

You can use both as soon as it's consitent.

So 'abc' and "abc" are valid and are the same.

While 'abc" and "abc' are not valid.

Petar Ivanov
  • 91,536
  • 11
  • 82
  • 95
0

As my opinion, they're no big difference. The only rule is:

var s = 'I can contain " " without \ ';
var s = "I can contain ' ' without \ ";

  • Well, you've answered the question, which is good. But you've not added any new information, which is bad. If you don't have anything new to contribute, just vote for one of the previous answers instead. – james.garriss Jul 13 '11 at 18:14