Wednesday, 26 April 2017

javascript - How does Node.js distinguish multiple parameters passed to a function?

For exmaple, I write the following code:






var http = require('http');

var server = http.createServer(function(req, res) {
res.end('Hello world!');
});

server.listen(8000, function() {
console.log('Serever started');

});





However, the definition of server.listen() is like this:



server.listen(port, hostname, backlog, callback);




listen() method has four parameters while only two parameters port and callback were passed in my code.
How the method knows that function(){console.log('Server started');} is 'callback' and not 'hostname?' Does it automatically check the type of parameters?

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...