2020 Update I wrote this back in 2010, and JavaScript has evolved a lot since. Since ES2015 (ES6), it's far simpler to define optional parameters to a function: function connect(hostname = "localhost", port = 80, method = "HTTP") { ... } // uses defaults for all