2

If often heard that I should declare String in Javascript in ' (single quotation marks) instead of " (double quotation marks) like in Java or other languages.

Unfortunately did i never ask why to do that.

The "best" answer I got until now was

It's more performant

Is that true? And why?

Philipp Sander
  • 10,139
  • 6
  • 45
  • 78

2 Answers2

0

In many languages using '' instead of "" is more performant because in string denoted by single quotes substitutions of escaped chars are not performed. This is not true in js. The reason there is a double quotation system, as far as I know, is that it allows you to avoid escaping "" in strings while using ''. Then it's a matter of taste.

ilmirons
  • 624
  • 6
  • 16
0

One reason might be the fact that it's more possible to need to use " in strings than '. So it's a good idea to use single quote to indicate a string literal, and save double quote to use inside the string.

For example in HTML the attribute of a value must be placed in double quotes like: <div class="myClass">.

so if you're creating such things dynamically you might need to use " in your string generation.

mehrandvd
  • 8,806
  • 12
  • 64
  • 111