Possible Duplicate:
When to Use Double or Single Quotes in JavaScript
Are there any differences between single and double quotes in javascript?
Possible Duplicate:
When to Use Double or Single Quotes in JavaScript
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.
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"'
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 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 would mostly use " unless in a position in where you can't escape it. ( It is neater to most developers, Don't ask why )
Also "$myVar"
in php will allow the string to have the variables value. ( I know its not javascript, but another example..
In bash,
echo "What is your name?\nMy name is $(whoami)."
will run the function / command whoami.
<button onclick="dosomething(\"test\")">Test</button> Won't work
<button onclick="dosomething("test")">Test</button> Won't work
<section id='"Where-As">
<button onclick="dosomething('test')">Test</button>
<!-- will work -->
</section>
P.S: Valid JSON objects should be using double quotes.
console.log('\n\n\n\n'); // Will give you \n\n\n\n as a string.
console.log("\n\n\n\n"); // Will give lines.