Below is a snippet from node url module source.
var punycode = require('punycode');
var util = require('util');
exports.parse = urlParse;
exports.resolve = urlResolve;
exports.resolveObject = urlResolveObject;
exports.format = urlFormat;
exports.Url = Url;
function Url() {
this.protocol = null;
this.slashes = null;
this.auth = null;
this.host = null;
this.port = null;
this.hostname = null;
this.hash = null;
this.search = null;
this.query = null;
this.pathname = null;
this.path = null;
this.href = null;
}
As you can see, the 'Url' is used before function 'Url' was defined. As far as I know this is not valid javascript, but it works ok.
Can someone tell me why this is ok? And why node writers love this convention?
EDIT : Thanks. I had no understanding of 'function hoisting' because the former title was the wrong question, modified.