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.
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.
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.
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.