开发者

Do "" and '' have different meanings in JavaScript? [duplicate]

This question already has answers here: Closed 12 years ago.

Possible Dup开发者_如何学JAVAlicate:

When should I use double or single quotes in JavaScript?

Do "" and '' have different meanings in JavaScript?

Because I keep seeing those two usages in jQuery, for instance:

$("")

and

$('')


No, they mean the same thing; they are both just JavaScript string literals.

Having have multiple different quote styles is useful so that:

  • You can nest quotes without having to use escape sequences eg. "some string with 'single quotes' in it", or 'a string with "double quotes" in it', and
  • JavaScript strings can be conveniently used inside directly inside HTML, where double-quotes have a special meaning eg <button onclick="alert('foo')">Click me</div>


Read about strings in JavaScript. There is no difference.

But as HTML properties are often defined with double-quotes, I would use single-quotes, which makes code like

$('<a href="someurl" />') 

easier to write.

Use the one with which you have less characters to escape inside the string.


Nope. It means the same.


They both are string delimiters. The only difference is if you can use " to enclose a string with ' in it, and you can use ' to enclose a string with " in it.


You can use either. I recommend sticking to one standard though throughout your project, things can sometimes get a little messy when interchanging between them when combining with server side code.


Outside of a string literal, No. Inside of a string literal, Yes.


No... since isn't possible use "" inside "", the "" and '' make a good combination when need quote a string inside another.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜