Hi,
Are there any differences between single and double quotes in javascript?
Hi,
Are there any differences between single and double quotes in javascript?
No, is the right answer most of the time. However if you want to write valid JSON, then you should use double quotes for object literals.
One is slightly wider, so you may have a few extra characters disappear to the right (as opposed to the slimmer version) in your favourite IDE.
Seriously though, I always use ', because if I need to quote a HTML element attribute, I always use " and I can't be bothered escaping like so
var html = "<a href=\"http://www.example.com\">hello</a>"
No, except in double quotes you can put single quotes.
e.g. "Don't not do this"
And in single quotes you can put double quotes.
e.g. 'John said "Do this"'
No difference. Just make sure you close the string with whatever you open it with.
Much more sensible to me than other languages (looking at you, C# and PHP...) where single quoted strings are either character literals, or don't expand escaped characters.
you should use " always unless in an element..
<button onclick="dosomething(\"test\")">Test</button> Wont work
<button onclick="dosomething("test")">Test</button> Wont work
<button onclick="dosomething('test')">Test</button> will work