Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

javascript

Possible Duplicate:
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

$('')
like image 927
Richard77 Avatar asked Aug 25 '10 16:08

Richard77


People also ask

What is === means?

The strict equality operator ( === ) checks whether its two operands are equal, returning a Boolean result. Unlike the equality operator, the strict equality operator always considers operands of different types to be different.

What does || stand for in JavaScript?

The logical OR ( || ) operator (logical disjunction) for a set of operands is true if and only if one or more of its operands is true. It is typically used with boolean (logical) values.


2 Answers

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>
like image 197
Brian Campbell Avatar answered Nov 15 '22 22:11

Brian Campbell


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.

like image 37
Felix Kling Avatar answered Nov 15 '22 22:11

Felix Kling