0

What is difference between 'string' and "string"?

For example, I use

alert('abc') and alert("abc")

document.getElementById('id') and document.getElementById("id")

I don't see any difference.

Lix
  • 47,311
  • 12
  • 103
  • 131
nicael
  • 18,550
  • 13
  • 57
  • 90

2 Answers2

6

There is no difference between them in javascript.

It is used to escape from escaping the quotes by using the alternative.

Like:

'some string "some here"';

"some string ' some here'";

You don't need to escape them using \ as in most language.

Amit Joki
  • 58,320
  • 7
  • 77
  • 95
4

There is no difference in JavaScript. Other languages handle single and double quotes differently. For example, with PHP, you can use double quotes to perform variable substitution.

One thing that might be relevant is the JSON (JavaScript Object Notation) spec in which all strings should be wrapped with double quotes. Most languages will be able to handle both types of quotes in the same manner, but if you need to have a 100% valid JSON object then you'll need to use double quotes.

Lix
  • 47,311
  • 12
  • 103
  • 131