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

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.


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>

Tags:

Javascript