I will use Node.js as an example but I see this in many docs:
(From the net module documentation):
net.createConnection(port, [host], [connectListener])
Creates a TCP connection to port on host. If host is omitted, 'localhost' will be assumed. The connectListener parameter will be added as an listener for the 'connect' event.
This is followed with example code such as the following:
a = net.createConnection(8080, function(c){
console.log('do something');
});
My question is that the createConnection function takes from 1 - 3 parameters. Above, I passed in two. How is it that Node is able to know the function argument I passed in is meant as the connectListener argument and not the host argument?