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.
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'
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.
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\""
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.
As my opinion, they're no big difference. The only rule is:
var s = 'I can contain " " without \ ';
var s = "I can contain ' ' without \ ";
精彩评论