Question:
Is there any difference between these two blocks of code?
sam
2014-10-11 16:18:44 UTC
My code crashes when I use the first few lines of code. But when I replace is with the other lines of code, which appear to be the exact same character for character, it works. Can you spot any differences between the two? I'm starting to feel like i'm crazy

1 - Causes error:

function serveStaticFile(res, path, contentType, responseCode){
if (!responseCode) reponseCode = 200;
fs.readFile(__dirname + path, function(err, data){
if (err){

2 - Doesn't cause error:

function serveStaticFile(res, path, contentType, responseCode){
if(!responseCode) responseCode = 200;
fs.readFile(__dirname + path, function(err, data){
if(err){
Three answers:
2014-10-11 16:26:43 UTC
Those two pieces of code are identical to the computer. If you're getting an error, it's being caused elsewhere.



In terms of actual difference, the only difference I see is that there's a space after the if statements in the first one, but no spaces after the if statement in the second. This shouldn't cause a problem though.
Daniel B
2014-10-11 16:26:38 UTC
The only difference between the two is the space after both ifs in the first block, but that should cause an error.
Gary
2014-10-11 16:32:49 UTC
syntax 2nd n 4th lines of code.

Yes i think its syntax i do not understand the code and do not know if your running direct application, emmulating, or communicating.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...