Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Difference between " and '

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 :)

Problem courtesy of: nalyd bob

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.

Solution courtesy of: ruakh

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Difference between " and '

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×