Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialnb11
17,552 PointsClarity on single and double quotation marks in Node.js?
HI,
I would just like to find out why sometimes in the videos a single quotation is used and sometimes a double, like in the code written below:
var Profile = require("./profile.js");
//Handle HTTP route GET / and POST / i.e Home
function home(request, response) {
//if url === "/" && GET
if(request.url === "/") {
//show search
response.writeHead(200, {'Content-Type': 'text/plain'});
response.write("Header\n");
response.write("Search\n");
response.end('Footer\n');
//if url == "/" && POST
//redirect to /:username
}
}
Like the 4 response lines towards the bottom, the first type one has single ' ', then the next 2 have a double " " and the last a single ' '. Is there a specific reason for this or do they need to be like this for the code to work correctly?
3 Answers
Iain Simmons
Treehouse Moderator 32,305 PointsThe short answer is that it doesn't really matter, as long as you escape quotes within a quoted string using the same type (escape single quotes in a single quoted string, etc).
Note that JSON requires double quoted strings for everything though.
nb11
17,552 PointsChyno Deluxe, thank you for the link on how to include code correctly, didn't know how to do that!
Iain, thank you for the clarity, appreciate the help.
Dan Lauby
7,897 PointsAlso, in the beginning of the video Andrew copy and pasted example code for creating the server from the Node docs site (single quotes). Then he altered the example code and he used double quotes.
Chyno Deluxe
16,936 PointsChyno Deluxe
16,936 Points//Fixed Code Presentation
How to post code