Last active
March 23, 2016 02:30
-
-
Save conorhastings/97c2db126c7d36a3a306 to your computer and use it in GitHub Desktop.
Node allows use of const (but not let) outside of strict mode but does not seem to respect block scoping
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* In this version without use strict declaration 'SyntaxError: Identifier 'text' has already been declared' is given | |
*/ | |
const http = require('http'); | |
const hostname = 'localhost'; | |
const port = 2001; | |
http.createServer((req, res) => { | |
if (req.url === '/favicon.ico') { | |
return; | |
} | |
const query = req.url.includes("?") && req.url.split('?')[1].split('='); | |
res.writeHead(200, { 'Content-Type': 'text/plain' }); | |
if (query[1] === 'true') { | |
const text = 'Hello World'; | |
res.end(text); | |
} | |
else { | |
const text = 'Goodbye World'; | |
res.end(text); | |
} | |
}).listen(port, hostname, () => { | |
console.log(`Server running at http://${hostname}:${port}/`); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const http = require('http'); | |
const hostname = 'localhost'; | |
const port = 2001; | |
http.createServer((req, res) => { | |
if (req.url === '/favicon.ico') { | |
return; | |
} | |
const query = req.url.includes("?") && req.url.split('?')[1].split('='); | |
res.writeHead(200, { 'Content-Type': 'text/plain' }); | |
if (query[1] === 'true') { | |
const text = 'Hello World'; | |
res.end(text); | |
} | |
else { | |
const text = 'Goodbye World'; | |
res.end(text); | |
} | |
}).listen(port, hostname, () => { | |
console.log(`Server running at http://${hostname}:${port}/`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment