Difference between " and '
Problem
Possible Duplicate:
When to Use Double or Single Quotes in JavaScript
single quotes versus double quotes in js
I'm trying to build a Node.js Express web application, and in the tutorial they use '
instead of "
quite often, but there is no explanation why.
Can someone please explain the difference? Is this specific to JavaScript, or does it apply to other languages too?
Example:
app.configure('dev')
app.get("/", function (req, res)
Thanks :)
Solution
In JavaScript, both are equivalent. The only difference is that inside a single-quoted String you don't have to escape "
, and vice versa:
'dev' === "dev"
'd"v' === "d\"v"
'd\'v' === "d'v"
Most other languages distinguish the two in some way. For example, in Bash and Perl, ''
prevents variables from being expanded inside, so 'a$b'
is the actual string a$b
, whereas "a$b"
is the string consisting of a
plus the value of the variable b
. In C, C++, C#, and Java, ''
is used to create a single character constant, so that 'a'
means the character a
whereas "a"
means a string containing that character.
Discussion
View additional discussion.