开发者

Please explain about quotes in the JavaScript language [duplicate]

开发者 https://www.devze.com 2023-03-19 16:58 出处:网络
This question already has answers here: Closed 11 years ago. Possible 开发者_开发百科Duplicate: When to Use Double or Single Quotes in JavaScript
This question already has answers here: Closed 11 years ago.

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 \ ";

0

精彩评论

暂无评论...
验证码 换一张
取 消