I am new to node.js and I'm having trouble understanding some of the things that I'm seeing. What does it mean when a variable's || operator is used in the following situations?
var server = function(config) {
config = config || {};
var server_root = config.server_root || '';
// ...
}
Also, I am coming from C# where all types and stuff are all neatly named and defined, so I'm kind of curious how the calling function knows what the type of config is in the first place. In the sample code I'm looking at, it is called like this:
// I guess this is adding a new start function to the server "class"
server.start = function(config) {
var instance = new server(config);
instance.start();
return instance;
};
// and here is where the start function is called. But how do I know what the type of the config is???
server.start({
port:8080,
preRequest: function(json,req,res) { ... },
postRequest: function(json,req,res) { ... }
});